Does Xcode have code autoformat feature?

There isn't really an autoformat option in Xcode.

There is an option ^I (Control-I) to re-indent the code, which will re-align the code according to the tab width set in your preferences, but that's about as far as it goes.

You might have better luck with a text editor like TextMate? I don't know for certain, but I know it supports Objective-C and has some macros, there may be a reformat option?


Yes Xcode 4 has an autoformat feature.

Try following:

  1. Select text. CMD+A.
  2. Press CTRL+I .

Please also see here: Fix code indentation in Xcode


One trick is to select the code (either "select all" or just the section you want to re-format) - then cut, then paste it back. This triggers the automatic code formatting in the Xcode editor.