How to format code in Xcode?

XcodeFormatKeyboard ShortcutsCode Formatting

Xcode Problem Overview


I wonder how can I format my code to align it neatly? Does it have a feature similar to Eclipse's ctrlshiftf?

Xcode Solutions


Solution 1 - 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.

https://i.stack.imgur.com/NdM0u.jpg" width="450" />

Solution 2 - Xcode

Key combination to format all text on open file:

Cmd ⌘ A + Ctrl I

Solution 3 - Xcode

  1. Select the block of code that you want indented.

  2. Right-click (or, on Mac, Ctrl-click).

  3. Structure → Re-indent

Solution 4 - Xcode

I would suggest taking a look JetBrains AppCode IDE. It has a Reformat Code command. I have come from a C# background and used Visual Studio with Jetbrains Resharper plugin, so learning AppCode has been a pleasure because many of the features in Resharper also exist in AppCode!

Theres too many features to list here but could well be worth checking out

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJames RaitsevView Question on Stackoverflow
Solution 1 - XcodePiotr KochańskiView Answer on Stackoverflow
Solution 2 - XcodeJ. CostaView Answer on Stackoverflow
Solution 3 - XcodeDairView Answer on Stackoverflow
Solution 4 - XcodesuperlogicalView Answer on Stackoverflow