Swift formatter extension for Xcode 🔨
… Although, technically, this isn't actually a formatter—it's an Xcode extension that goes and gets your favorite formatter and applies it to your Swift code with a config file that lives somewhere on your machine.
Download the latest release.
Enable the Swift Fixer extension by checking Swift Fixer under System Preferences / Extensions / Xcode Source Editor.
Swift Fixer has three configurable parameters:
- Enabled
- Per formatter
- Whether the selected formatter gets run when you run the Swift Fixer extension in Xcode.
- Linked Configuration
- Per formatter
- The config file the selected formatter refers to when formatting your Swift in Xcode.
- Note that when you specify a config file, that file is linked, not imported. So when you specify
~/.swiftlint.yml
as Swift Lint's config file, future changes to~/.swiftlint.yml
will take effect when you run the Swift Fixer extension in Xcode. - Also note that you must specify a configuration file in order to enable a formatter.
- Order
- General
- The order in which enabled formatters are run.
- This is important because if you prefer to run two or more formatters to format your Swift code, the order in which those formatters run can affect the end result.
- You can specify an order by dragging and dropping cells in the application window.
- Why would you ever want to run two consecutive formatters on your code?
- About the only use case I can think of is running
swiftlint --fix
to clean up fixable linting messages thatswift-format
couldn't take care of. Beyond that, I have no idea why anyone would want to run two formatters. But hey, the capability's there. 🤷♂️
- About the only use case I can think of is running
You can activate Swift Fixer in Xcode by clicking Format Swift code under Editor / Swift Fixer, but you'll probably find it more convenient to call with a keyboard shortcut, which can be configured through Xcode.