Skip to content

Instantly share code, notes, and snippets.

@ralfebert
Last active September 16, 2021 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralfebert/62c1159175f5f071241fcf30c60bfd61 to your computer and use it in GitHub Desktop.
Save ralfebert/62c1159175f5f071241fcf30c60bfd61 to your computer and use it in GitHub Desktop.

FB9624610: Formatting Swift code using an external tool like swiftformat on Save

I am using the splendid command-line tool swiftformat (https://github.com/nicklockwood/SwiftFormat) to format my Swift code.

For my, the perfect integration point for this tool would be on Save in Xcode. In that way the formatting would not interrupt my editing, but I can see/check the changes done by the formatter, but never forget to format a file after editing.

I'd like to suggest a configuration option for Xcode that allows to configure it in such a way that, when I press save (cmd S) it saves the file and then runs a command line utility and reloads the file - or a capability for an Xcode source code editor extension to do such an operation.

One alternative could be to do it at build time which is possible to configure currently using a Build phase (https://github.com/nicklockwood/SwiftFormat#xcode-build-phase), but unfortunately, with this setup one loses all the undo history in Xcode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment