Xcode: Adjusting indentation of auto-generated braces?

Viewed 18277

Code auto-generated by Xcode seems to have the opening brace on the same line by default:

@interface Controller : NSObject {

}

I'd like the opening brace on a line of its own, like this:

@interface Controller : NSObject 
{

}

This applies in general to any method / class auto-generated by Xcode. In Xcode preferences I have "Indent solo { by" set to 0: alt text

How can I fix this?

6 Answers

The New Project and New File commands don't really generate any code; they fill in templates.

You'll need to create your own templates (probably based on Apple's) with the changes you want.

In Xcode 3.1, the stock templates are in /Developer/Library/Xcode. You'll put your modified copies in ~/Library/Application Support/Developer/Shared/Xcode. Pay attention to the subfolders of those folders.

Read this: XCCodeSenseFormattingOptions

This document describes all the formatting options that auto-complete will use for brace and argument style. Here are mine:

    XCCodeSenseFormattingOptions =     {
    BlockSeparator = "\\n";
    PreMethodDeclSpacing = "";
};

If you want to have your preferred style in all situations, you need a combination of Laughing_Jack's answer and Peter Hosey's answer. In addition to what Peter Hosey said, you may also like to know that the Cocoa Touch file templates are in the following location. You can copy that directory to your custom templates too:

/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/File Templates/Cocoa Touch Classes/

The Xcode User Defaults give you your style when typing out code by hand, the file templates provide it when auto-generating a new class etc.

Related