New Objective-C Literal Syntax for NSArray, NSDictionary 是以@字符开始的方式简单地创建数组、字典、NSNumber常量。

代码如下:

NSNumber *n1 = @1000;  // [NSNumber numberWithInt:1000] 
NSNumber *n2 = @3.1415926; // [NSNumber numberWithDouble:3.1415926]
NSNumber *c = @'c'; // [NSNumber numberWithChar:'c']
NSNumber *b = @YES; // [NSNumber numberWithBool:YES]

// `unsigned` (`u`) 以及 `float` (`f`)
NSNumber *f = @2.5f;
NSNumber *nu = @256u;


NSArray *words = [NSArray arrayWithObjects:@"list", @"of", @"words", nil];
NSArray *words = @[@"list", @"of", @"words", @123, @3.14];

NSDictionary *dict = @{
  @"key": @"value",
  @"name": @"Joris",
  @"n": @1234,
  @3: @"string"
};
评论模块尚未加载