Getting Xcode to put opening braces on a new line

By default Xcode (the Apple Developer IDE) puts opening braces at the end of the current line like so:

if ( condition ) {
     // code here...

However I have been working on projects for years with a different convention:

if ( condition )
    // code here...

Of course developers have different preferences here. One is not right and the other wrong – that is dictated by a company or by a project, or by the consensus of the developers starting a new project. Once a convention is in place then it must be adhered to for the life of the project. And of course a decent IDE will work with developers preferences.

So – how do we get Xcode to support this alternate convention? The problem being that there is no UI preference to set this.

To change this preference the quick way:

Open the Terminal App and paste the following code:

defaults write XCCodeSenseFormattingOptions -dict BlockSeparator "\n"

Then restart Xcode. Thats it.

What does this do? It places a new entry in a plist file that is located in your user Home Directory. Home > Library > Preferences >

Next time you start coding in Xcode it will autocomplete with opening braces on a new line.

Be Sociable, Share!