DEV Community

Michael Lustig - halfjew22@gmail.com
Michael Lustig - halfjew22@gmail.com

Posted on

Format Swift on Save - AppCode with swift-format

Coming from WebStorm and TypeScript land, I got sick of not having auto-formatted code while working on a small Front End SwiftUI project. After finally figuring out how to autoformat my Swift code, I had to share as NO RESULTS ONLINE WERE HELPFUL!

See below and linked video. Let me know if you have any questions or suggestions for improvements.

  1. brew install nshipster/formulae/swift-format
  2. Create external tool
  3. Name it swift-format
  4. Under Tool Settings > Arguments: --in-place $FilePath$
  5. Advanced Options > Uncheck Open console for tool output
  6. Click OK
  7. Click Apply
  8. Create a Keymap for your new external tool by searching for “swift-format” and double clicking on the result
  9. Open any code file
  10. Edit > Macros > Start Macro Recording
  11. Invoke the keycap from step 6 and then save your file
  12. Click the stop button in the bottom right hand of your editor to stop the macro
  13. LAST STEP Assign the ⌘S keymap to your new macro

Top comments (0)