Since I used to spend most of my day developing in TextMate I became very familiar with how to customize the environment to suit my needs, which enhanced source code formatting was one of them. Xcode allows similar abilities to customize your environment as TextMate via "Edit User Scripts". Below I will outline how to configure Xcode to enable greater control over formatting source code.
There are two packages that must first be installed prior to making any changes in Xcode: MacPorts and bcpp.
bcpp is a source beautifier for C, C++ and Objective-C developed by Steven De Toni and is maintained by Thomas E. Dickey. From the MacPorts site, MacPorts is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system".
You will first need to install MacPorts if you don't already have it on your system.
Once MacPorts has been installed, you can just type “sudo port install bcpp” from Terminal to install bcpp on your system. By default, MacPorts will place bcpp into /opt/local/bin on your mac.
Now to setup bcpp inside Xcode...
1. Select the User Scripts Editor:
2. From the menu in the lower left corner of the editor select "New Shell Script"
Note: You can optionally create a new folder to place your custom scripts. I place my custom scripts in a folder called "Personal".
3. Name the script "Objective-C Beautify"
4. On the right side of the editor make the following changes:
Input: Entire Document
Directory: Selection
Source window: /opt/local/bin/bcpp -fnc ~/.bcpp
Output: Replace Document Contents
Errors: Display in Alert
5. Change the shortcut to something that you will remember and that's not already mapped to something else in Xcode.
Here's the final result: