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 โธ 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, click on Keyboard and switch to the Shortcuts tab. Select App Shortcuts, then hit the + button. Select Xcode, enter Format Swift Code
and set your Shortcut.๐
Installing Apple Swift Format (Xcode or Mint)
if you are using Xcode 11.4 (Swift 5.2), you can check out and build swift-format using the following commands:
git clone -b swift-5.2-branch https://github.com/apple/swift-format.git
cd swift-format
swift build
You should see this
[207/207] Linking swift-format
๐๐๐
If you dint have Homebrew, install here
brew install mint
mint install apple/swift-format@swift-5.2-branch
You should see this
๐ฑ Cloning swift-format swift-5.2-branch
๐ฑ Resolving package
๐ฑ Building package
๐ฑ Installed swift-format swift-5.2-branch
๐ฑ Linked swift-format swift-5.2-branch to /usr/local/bin
๐๐๐
swift-format -v
0.0.1
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 | AngelList | Twitter | Github | Medium | Stackoverflow