Need help with Xcode-formatter?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

195 Stars 25 Forks 41 Commits 3 Opened issues


Simple automatic code formatter for Xcode

Services available


Need anything else?

Contributors list

# 404,925
33 commits
# 571,306
5 commits


Why a code formatter

A common problem with large iOS projects is the lack of support for a shared set of formatting rules. This leads over the time to unreadable and hard to maintain sources files.

Xcode Formatter uses uncrustify to easily format your source code as your team exactly wants it to be!

Simply add the CodeFormatter directory in your Xcode project to get :

  • Xcode shortcut-based code formatting: a shortcut to format modified sources in the current workspace
  • automatic code formatting: add a build phase to your project to format current sources when application builds
  • all sources formatting: format all your code with one command line
  • your formatting rules shared by project: edit and use a same configuration file with your project dev team

1) How to setup the code formatter for your project

Install uncrustify

The simplest way is to use brew:

$ brew install uncrustify

To install brew:

$ ruby -e "$(curl -fsSkL"

Check that uncrustify is located in /usr/local/bin/

$ which uncrustify

If your uncrustify version is lower than 0.60, you might have to install it manually since modern Objective-C syntax has been added recently, see this post :

Add CodeFormatter directory beside your .xcodeproj file

CodeFormatter directory location

Check that your Xcode application is named "Xcode" (default name)

You can see this name in the Applications/ directory (or your custom Xcode installation directory). Be carefull if you have multiple instances of Xcode on your mac: ensure that project's one is actually named "Xcode"!

(Why this ? This name is used to find currently opened Xcode files. See CodeFormatter/Uncrustify_opened_Xcode_sources.workflow appleScript).

Install the automator service Uncrustify_opened_Xcode_sources.workflow

Copy this file to your ~/Library/Services/ folder (create this folder if needed).

Be careful : by double-clicking the .workflow file, you will install it but the file will be removed! Be sure to leave a copy of it for other users.

2) How to format opened files when building the project

Add a build phase "run script" containing the following line:

sh CodeFormatter/scripts/

Add build phase

3) How to format opened files with a shortcut

Add a shortcut to the UncrustifyopenedXcode_sources service

Go to Xcode > Services > Services preferences :

Create service shortcut

And set your shortcut :

Choose service shortcut

4) How to format files in command line

To format currently opened files, use

$ sh CodeFormatter/scripts/

To format all files, use

$ sh CodeFormatter/scripts/ PATH

PATH must be replaced by your sources path.

5) How to change formatter’s rules

Edit CodeFormatter/uncrustify_objective_c.cfg

You can use UniversalIndentGUI ( to simplify edition.

6) FAQ

When formatting the current sources, an unknown error occurs and shows my code. What can I do?

Uncrustify (version 0.59) does not handle apple new literals for creating NSDictionary and NSArray like:

NSDictionary *dictionary = @{@0 : @"red",
                             @1 : @"green",
                             @2 : @"blue"};

Until a new version of uncrustify fixes this issue, you can use the old way with those literals:

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"red", @1, 
                                                                       @"green", @2, 
                                                                       @"blue", @3, 

I want to have a single configuration file for all my Xcode projects, is it possible?

Yes, everything is possible. Just move your configuration file to your home directory: '~/.uncrustify//uncrustify_objective_c.cfg' and remove 'CodeFormatter' directory from your project. If the configuration file is not found in project directory, this global file is used.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.