Is there anyway to format the code in Xcode like you can do in Eclipse or Netbenas. I have not found any option in menu, is there any hot key for this or its simply not in Xcode?
Select some text and then: Edit->Format->Re-Indent
You can bind this to a hotkey in the preferences.
In Xcode 4, it's been moved to Editor > Structure > Re-Indent
command (and has a default shortcut of CTRL+I ).
Other than re-indentation (Edit > Format > Re-Indent), not really. However, Xcode does have support for scripts (the menu to the right of the Window menu), so you could conceivably write a script that formats your code how you like it.
Edit: here are some links that touch on this subject:
My personal favorite code formatter is Uncrustify. It has many, many options, so I also suggest you download UniversalIndentGUI, a GUI to help set Uncrustify's behavior to your liking.
Here are the shortcuts, to format the code in Xcode
1.Format entire code (entire class/controller)
select the entire code and press ⌘+| on mac to format your code.
2.Format particular block of code
select the code and press
⌘+] for right move and ⌘+[ for left move
Note : as per @JavierGiovannini sugesstion you can do using Editor Menu option
3.Select code --> Go to Editor --> Structure --> Re-Indent
Not saying this is best approach, but for completeness, if you cut and then paste the code back in, Xcode will automatically format it for you.
In v.4 you can make some adjustments through xCode preferences...
You can also highlight the code you want to re indent, and use the re-indent command
XCode 8 Extensions
Another option is to use an extension like Swimat. Does the job for me. However, the caveat is that it does not format on save due to the restrictive Xcode Extension APIs, but they're trying to find a workaround.
来源:https://stackoverflow.com/questions/1510915/code-formatting-in-xcode