(转)Apple LLVM 4.0的新特性

原文:

Xcode now includes the Apple LLVM Compiler version 4.0, including the following newObjective-C language features:

 - Default @synthesize: automatically synthesizes an @property when unimplemented
 - Objective-C literals: create literals for NSArray, NSDictionary, and NSNumber, just the same as the literals for NSString
 - Objective-C container subscripting: use '[]' syntax to access containers such as NSArray and NSDictionary

译文

 

  • @synthesize: 自动为@property添加synthesize (尼玛!!! 我们已经期待很久了!!!)
  • 语法: 创建NSArray, NSDictionary, NSNumber的时候, 可以像NSString那样写 (不懂? 下面解释!)
  • 容器下标(?): 用’[]‘来访问容器(例如NSArray和NSDictionary), 就像你在第一节C语言课上学的”arr[0]“, “arr[1]“那样. 不过这个似乎是允许在’[]‘中填入字符串的(NSDictionary).

下面举例解释下第二条:

NSArray

Previously:

array = [NSArray arrayWithObjects:a, b, c, nil];

Now:

array = @[a, b, c];

NSDictionary

Previously:

dict = [NSDictionary dictionaryWithObjects:@[o1, o2, o3] forKeys:@[k1, k2, k3]];

Now:

dict = @{k1: o1, k2: o2, k3: o3};

NSNumber

Previously:

NSNumber *number;
number = [NSNumber numberWithChar:'X'];
number = [NSNumber numberWithInt:12345];
number = [NSNumber numberWithUnsignedLong:12345ul];
number = [NSNumber numberWithLongLong:12345ll];
number = [NSNumber numberWithFloat:123.45f];
number = [NSNumber numberWithDouble:123.45];
number = [NSNumber numberWithBool:YES];

Now:

NSNumber *number;
number = @'X';
number = @12345;
number = @12345ul;
number = @12345ll;
number = @123.45f;
number = @123.45;
number = @YES;

One thought on “(转)Apple LLVM 4.0的新特性

Leave a Reply

Your email address will not be published. Required fields are marked *