Integrating swift-format into Xcode
Please read below if you're formatting your Swift code in Xcode with Ctrl-I and want to try swift-format instead of built-in formatting.
- apple/swift-format[@your-version-is-here] installed and made available via Mint
-
Double-click "Swift Format.workflow" and "Swift Format Helper.workflow" to install both in ~/Library/Services.
-
In System Preferences > Keyboard > Shortcuts > Services:
- Assign Ctrl-Option-I (or whatever else) to General > Swift Format
- Assign Ctrl-Option-Command-I to Text > Swift Format Helper (don't change this shortcut)
-
In Xcode select a block in .swift file and select Xcode > Services > Swift Format. (This step might be required for the keyboard shortcuts to start working).
- If you get a prompt about assistive devices, allow whatever asked in System Preferences (Security & Privacy > Privacy > Accessibility > Allow the apps below to control your computer)
- If you get errors even after that, try adding /Applications/Automator manually to the Accessibility control list (see above).
-
You can override default swift-format settings via
.swift-format
-
You can override default Mint version of swift-format by placing it in
.swift-format-mint-version
somewhere up in the file hierarchy.
- Level of indentation of the result depends on the app:
- To make it properly indented in Xcode you have to enable "Indent when typing" in Preferences > Text Editing > Indentation > Syntax-Aware Indenting (optionally enabling "Re-indent on paste" in the same group)
- With other apps indentation level of the resultl is typically reset to zero
- Indentation in swift-format should match your Xcode Settings in Syntax-Aware Indenting