views:

172

answers:

2

I know this is a fairly contentious issue amongst programmers, but when developing I like my IDE to position the opening curly bracket underneath the method/interface/control declaration, for illustrative purposes: -

This is how Xcode automatically generates skeleton methods with the { at the end: -

-(void) isTrue:(BOOL)input {
    if(input) {
        return YES;
    }
    else {
        return NO;
    }
}

This is how I like to lay out my code (which I believe is called the Allman style): -

-(void) isTrue:(BOOL)input 
{
    if(input) 
    {
        return YES;
    }
    else 
    {
        return NO;
    }
}

I'm just wondering if there's any configuration switch in Xcode to enable this style of development? It's really annoying when typing out if/else statements as it tends to auto-complete the else clause with the { at the end of the line which just looks silly if you like developing with them underneath.

Or am I being unreasonable? Is Objective-C supposed to adhere to a standard defined by Apple?

+7  A: 

Take a look at:

http://stackoverflow.com/questions/392749/xcode-adjusting-indentation-of-auto-generated-braces

Apple Xcode User Defaults

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

This should at least solve your problem after if, for, or while statements.

WhirlWind
Absolutely spot on, thanks for your reply!
djhworld
+2  A: 

After digesting the helpful information from WhirlWind above (thanks), the resulting snippet (just cut and paste into terminal) is:

defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict BlockSeparator "\\n" PreMethodDeclSpacing ""

Stupid backslash quoting. When typed at the terminal, there should be TWO exactly TWO backslashes in the block separator.

Warren P
Yeah I got a bit confused about that, I did something similar to the above but used the -dict-add flag for each key/value pair
djhworld