Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format code in Xcode? [duplicate]

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

like image 462
James Raitsev Avatar asked Jul 01 '11 02:07

James Raitsev


People also ask

Does Xcode have Formatter?

In the Xcode menu click [Editor] -> [Swimat] -> [Format] then the current active file will reformat. You can also create a hot-key in [Xcode] -> [Preferences..]

How do I auto align code in Xcode?

Xcode can fix this with one shortcut: select the code you want to fix, then press Ctrl+I to reindent it.


1 Answers

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.

like image 73
Piotr Kochański Avatar answered Nov 03 '22 05:11

Piotr Kochański