Created
July 26, 2012 19:05
-
-
Save flandy84/3183844 to your computer and use it in GitHub Desktop.
"modern Objective-C" syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//"modern Objective-C" syntax | |
//new enum-macros for better autocompletion, switch statement, more precise warnings, ... | |
typedef NS_ENUM(NSInteger, MyViewContentMode) { | |
MyViewContentModeLeft, | |
MyViewContentModeRight, | |
MyViewContentModeTopLeft, | |
MyViewContentModeTopRight, | |
MyViewContentModeBottomLeft, | |
MyViewContentModeBottomRight, | |
}; | |
typedef NS_OPTIONS(NSUInteger, MyViewAutoresizing) { | |
MyViewAutoresizingNone = 0, | |
MyViewAutoresizingFlexibleLeftMargin = 1 << 0, | |
MyViewAutoresizingFlexibleWidth = 1 << 1, | |
MyViewAutoresizingFlexibleRightMargin = 1 << 2, | |
}; | |
@interface MyModernClass() //Class extension: Private interface | |
@property(nonatomic, strong) NSNumber* doubleNumber; | |
@end | |
@implementation MyModernClass | |
-(void)startAsynchronous{ | |
_doubleNumber = [NSNumber numberWithDouble: 4.6]; | |
[self doSomethingLaterDeclared]; | |
} | |
-(void)doSomethingLaterDeclared{ | |
//literals | |
NSArray* array = @[@"one", @"two"]; | |
NSDictionary* dic = @{@"key1":@"value1", | |
@"key2":@YES, | |
@"key3":@3.0}; | |
NSDictionary* jsonPostBodyDic = @{@"update":@{ | |
@"app":@{ | |
@"bundle_id":@NO, | |
@"version":@[@1, @0, @0] | |
}, | |
@"last_updated": [NSNull null] | |
} | |
}; | |
//container subscripting | |
NSNumber* boolNumber = dic[@"key2"]; //instead of [dic objectForKey:@"key2"]; | |
NSString* string = array[1]; //instead of [array objectAtIndex:idx]; | |
NSMutableDictionary* mutableDic = [NSMutableDictionary dictionaryWithDictionary:dic]; | |
mutableDic[@"key2"] = @"asd"; // instead of [mutableDic setObject:@"asd" forKey:@"key2"] | |
mutableDic[@"key4"] = @34.5f; // instead of [mutableDic setObject:@34.5f forKey:@"key4"] | |
NSMutableArray* mutableArray = [NSMutableArray arrayWithArray:array]; | |
mutableArray[1] = @"neu"; // instead of [mutableArray replaceObjectAtIndex:1 withObject:@"neu"]; | |
mutableArray[[mutableArray count]] = @"neuneu"; // instead of [mutableArray addObject:@"neuneu"];; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment