X-SwiftFormat extension for Xcode
brew install --cask x-swiftformat
X-SwiftFormat works as Xcode Extension to format your swift code. You will need to open this once to activate it π
a) You case use the Preview to see the format running in the app πͺ
b) You can export a configuration file ( .swift-format
) to use later π₯
Open System Preferences βΈ Privacy & Security βΈ Extensions βΈ Xcode Source Editor and make sure X-SwiftFormat is selected β
Open Xcode and use the Format Swift Code command in Xcodeβs Editor menu π
Open System Preferences βΈ PKeyboard βΈ Keyboard Shortcuts βΈ App Shortcuts, then hit the + button. Select Xcode, enter Format Swift Code
and set your Shortcut.π
if you are using Xcode 15 (Swift 6.0), you can check out and build swift-format using the following commands:
git clone -b release/6.0 https://github.com/apple/swift-format.git
cd swift-format
swift build
You should see this
Build complete! (50.00s)
πππ
If you did not have Homebrew, install here
brew install mint
mint install apple/swift-format@release/6.0
You should see this
π± Cloning swift-format release/6.0
π± Resolving package
π± Building package
π± Installed swift-format release/6.0
π± Linked swift-format release/6.0
πππ
swift-format -v
600.0.0
Command | Description |
---|---|
swift-format swift |
Display formatted code |
swift-format -i file.swift |
Overwrites formatted code |
swift-format -r folder |
Format all files in a folder |
swift-format -r -i folder |
Format all files in a folder and overwrites |
Check more info here: https://github.com/apple/swift-format
Iβm Rui Aureliano, iOS and macOS Engineer at OlΓ‘ Brothers. We make Sip π€
Linkedin | Twitter | Github | Stackoverflow