Skip to content

Instantly share code, notes, and snippets.

@preble
Created August 15, 2013 01:54
Show Gist options
  • Save preble/6237573 to your computer and use it in GitHub Desktop.
Save preble/6237573 to your computer and use it in GitHub Desktop.

Objective-C Bracing Style

I'm Adam Preble and this is the bracing style I like. Please don't use it unless you (a) like it, or (b) are contributing to a project of mine.

Rules

  • Braces go on the next line for:
    • Method definitions.
    • if blocks:
    • After case statements, but only if required by local variables within the case.
  • Braces go on the same line on:
    • @interface and @implementation lines, when defining instance variables.
    • switch blocks
    • When passing a block 'inline' (preferred style of passing blocks).

Example

@interface QRTEmbracer : NSObject {
    // I don't put ivars in my header files,
    // but if I did, they would be braced like this.
}
@end

@interface QRTEmbracer () {
    int _count;
}
@end

@implementation QRTEmbracer

- (instancetype)init
{
    if (self = [super init])
    {
    }
    return self;
}

- (void)animate
{
    [UIView animateWithDuration:1.0 animations:^{
        switch (_count) {
            case 0:
                ...
                break;
            case 1:
            {
                int zebras = _count * 2;
                ...
                break;
            }
        }
    }];
}

@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment