Apple LLVM 4.0的新特性

Posted by Elton's Blog on February 22, 2012

最新的LLVM 4.0添加了几个比较有用的特性:

  1. @synthesize: 自动为@property添加synthesize
  2. 语法: 创建NSArray, NSDictionary, NSNumber的时候, 可以像NSString那样写 (下面例子解释!)
  3. 容器下标: 用’[]‘来访问容器(例如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;

引自:http://seymourdev.com/?p=302#more-302