Code Formatting in Xcode

Using Xcode 4? Take a look at Code Formatting in Xcode 4

Working in Xcode I almost forgot how much I like IntelliJ’s code formatting tools. Luckily for me Mike Smith recently pointed out that UniversalIndentGUI can be used to setup your own code formatting in Xcode.

UniversalIndentGUI supports a large number of code formatting tools but Uncrustify seems to be the only one with objective-c support. An up to date build of Uncrustify (version 0.53) is included with UniversalIndentGUI so I did not need to build my own.

I setup a set of styling rules using UniversalIndentGUI’s live preview and saved the resulting config file. I was then able to add a set of custom user scripts in Xcode to run Uncrustify against the current file or selection. I found that I had to specify the source as objective-c to prevent Uncrustify form running some C/C++ styling rules which I did not want.

Uncrustify custom scripts in Xcode

Uncrustify custom scripts in Xcode


~/Applications/UniversalIndentGUI/indenters/uncrustify -l OC -q -c ~/Applications/UniversalIndentGUI/config/uncrustify_obj_c.cfg

Now I can quickly clean up most of the minor formatting inconsistencies which creep into my code. Now I just need to polish my config file until it better matches my expectations for code formatting. In defining my preferred code style I have tried to follow the example provided by:


My current config file for Uncrustify is available here: uncrustify_obj_c.cfg if you would like to use it as a starting point.

My config file is now also available as a gist: for anyone who would like to suggest improvements or create their own fork.

This entry was posted in Mobile and tagged , , . Bookmark the permalink.
  • Jason Kratz

    Wow. Talk about a timely post :) I just found this after getting really fed up with not being able to control source formatting in Xcode when working on iPhone code for the first time. I’m so used to what is in Eclipse and NetBeans and being able to control everything. Giving up that in Xcode is more than annoying.


  • Tobias Patton

    Would you care to publish you config file? Thanks.

    • jonah

      Sure thing, I’ve added a link to it to the bottom of the post. Hope you find it useful.

  • Tobias Patton


    If you pick up the latest source of uncrustify (0.54) and build it, there’s a new parameter:


    that will align objective-c multi-line messages so that the colons are aligned.

  • Derek Clarkson

    Hi, I’m just picking up Objective C and Xcode and was actually quite surprised at the lack of some formatting and refactoring tools I found. I’m coming from a Java/Eclipse world so I was quite used to extensive tools in these areas. Your posting has really helped with the formatting side of things.


  • Dmytro Bischak

    It works well!
    I’m using your config :)

  • Marcus Smedman

    Excellent, thank you very much!

  • Marcelo Castro

    Felt the same way as Derek. For those who came from Eclipse/Netbeans… code formatting is a real drawback for Xcode.

  • Jedidja

    Wow that definitely helps a lot. Really miss the Ctrl-K,D from Visual Studio for auto-formatting.

  • Andy Waite

    Is there any way to automate this so that uncrustify always runs when you save modifications to a file?

  • rh

    Just wanted to throw in my thanks – this makes the transition from VS a lot easier!

  • Pingback: Code Formatting in Xcode 4 | Carbon Five Community

  • Pingback: Formatting Objective C source files [closed] | PHP Developer Resource