How to format code in Xcode?
Select first the text you want to format and then press Ctrl+I.
Use Cmd+A first if you wish to format all text in the selected file.
Note: this procedure only re-indents the lines, it does not do any advanced formatting.
In XCode 12 beta:
The new key binding to re-indent is control+I.

Key combination to format all text on open file:
Cmd ⌘ A + Ctrl I