Tag: llvm

[教學]Objective-c LLVM 4.0 新用法

NSNumber

之前用法:

NSNumber *intNumber = [NSNumber numberWithInt:10];
 
NSNumber *doubleNumber = [NSNumber numberWithDouble:1.234567];
 
NSNumber *charNumber = [NSNumber numberWithChar:'x'];
 
NSNumber *boolNumber = [NSNumber numberWithBool:YES];

4.0 後新用法

NSNumber *intNumber = @1000;
 
NSNumber *doubleNumber = @1.234567;
 
NSNumber *charNumber = @'x';
 
NSNumber *boolNumber= @YES;

NSArray

之前用法:

NSArray *weekdays = [NSArray arrayWithObjects:@"monday", @"tuesday", @"wednesday", nil];
 
NSString *monday = [weekdays objectAtIndex:0];

4.0 後新用法

NSArray *weekdays = @[@"monday", @"tuesday", @"wednesday"];
 
NSString *monday = weekdays[0];

NSDictionary

之前用法:

NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:
 
@"ynjan", @"name",
 
@"www.ynjan.com", @"website",
 
nil];
 
NSString *name = [info objectForKey:@"name"];

4.0 後新用法

NSDictionary *info = @{
 
@"name": @"ynjan",
 
@"website": @"www.ynjan.com"
 
};
 
NSString *name = info[@"name"];
Tags : ,