Formatting keyboard shortcut in Xcode
Xcode can format your entire file with a single key bind. Here’s how.
Short answer: ⌘ + A then press ⌃ + I
Sometimes when you write code and you play together with the editor, using tab suggestions and working a bit speedier, you end up with code that looks and feels ugly. Code that is malformatted might be compiled just fine, but it gets hard to read very fast.
Manually formatting your code is an option, but also gets tedious fast.
That’s why nearly every major IDE has a code formatting feature that is waiting for you behind a keyboard shortcut.
Xcode is no exception to this rule.
In Xcode, you don’t format the entire codebase or the entire file like in other editors.
Here, it works on the text you’ve selected.
So you could select a block you want to be auto-formatted, or if you want to format the whole file, just select the entire content of the file with:
⌘ + A
And then you can auto-format by using:
⌃ + I
That’s it!
As you can see by some work in progress SwiftUI from my upcoming app Charon, the auto-format has made the code block much, much more readable.
Thank you for reading and happy formatting!
Update History
Published this article
To my knowledge... this article is published... effective immediately!
Created new article titled 'Formatting keyboard shortcut in Xcode'
Drafted the article and prepared for publishing.
About the author

Yann Gwenaël Berton
I’m passionate about creating software solutions that matter and have a real impact on people’s lives. Personally, I believe it’s an art to craft a user experience that leaves users astounded, and I’m constantly striving to improve my skills in this area.
Read more