Swift Format in Xcode 16
In Xcode 16, Apple quietly introduced the ability to format your Swift files using Swift Format. I’m a long-time user of SwiftLint, but having such a tool built into Xcode would be a great convenience, so I decided to give it a try. Here is my description of why I use such a tool, how well it works compared to the alternatives, and how I configured it for my own purposes.
[…]
The name Apple chose is logical but confusing. I had experimented with Nick Lockwood’s SwiftFormat a few years ago, but found that I preferred SwiftLint, so I stuck with the latter. When I saw that Xcode included Swift Format, I assumed that they had acquired Nick’s formatter but it appears to be a different tool, officially called swift-format. It’s downloaded as part of the toolchain when you install Xcode 16, so no further installation is required.
[…]
After reverting to the original code again, I chose Editor -> Structure -> Format File with ‘swift-format’[…]
This fixed the indentation and the whitespace issues. Interestingly, it split the long function call and definition over multiple lines, but still with more than one argument per line.
Previously:
1 Comment RSS · Twitter · Mastodon
A downside of using swiftlint -fix , and presumably any other formatted that runs during a build phase, is that it breaks the undo stack.