Confirmed users
198
edits
Line 3: | Line 3: | ||
== Code Style == | == Code Style == | ||
Our code style is based on [https://google.github.io/styleguide/objcguide.html Google's Objective C Style Guide], with a few exceptions and additions: | Our code style is based on [https://google.github.io/styleguide/objcguide.html Google's Objective C Style Guide], with a few exceptions and additions. The [https://www.mediawiki.org/wiki/Wikimedia_Apps/Team/iOS/ObjectiveCStyleGuide Wikimedia style guide] is also a good reference for things not covered here or in Google's guide. | ||
=== Method Declarations === | === Method Declarations === | ||
Line 62: | Line 62: | ||
// override | // override | ||
- (NSString*)pooh; | - (NSString*)pooh; | ||
</syntaxhighlight> | |||
=== NSObject Literals === | |||
Whenever possible, use <code>@</code> literals when creating immutable objects. Be careful not to pass <code>nil</code> values into container objects as this will cause a crash. | |||
<syntaxhighlight lang="Objective-C"> | |||
// Do | |||
NSArray* actions = @[@"AXPress", @"AXShowMenu", @"AXScrollToVisible"]; | |||
// Don't | |||
NSArray* actions = [NSArray arrayWithObjects:@"AXPress", @"AXShowMenu", @"AXScrollToVisible", nil]; | |||
// Do | |||
NSDictionary* keyValues = @{@"key1" : @"value1", @"key2" : @"value2"}; | |||
// Don't | |||
NSDictionary* keyValues = [NSDictionary dictionaryWithObjectsAndKeys:@"key1", @"value1", @"key2", @"value2", nil]; | |||
// Do | |||
NSNumber* isBest = @YES; | |||
// Don't | |||
NSNumber* isBest = [NSNumber numberWithBool:YES]; | |||
// Do | |||
NSNumber* life = @42; | |||
// Don't | |||
NSNumber* life = [NSNumber numberWithInteger:42]; | |||
</syntaxhighlight> | </syntaxhighlight> | ||