@符号不仅可以生成字符串,还可以生成其他数据类型如NSArray、NSDictionary和NSNumber,是一种简洁快速的用法。
// NSArray array = [NSArray arrayWithObjects:a, b, c, nil]; array = @[ a, b, c ]; // NSDictionary dict = [NSDictionary dictionaryWithObjects:@[o1, o2, o3] forKeys:@[k1, k2, k3]]; dict = @{ k1 : o1, k2 : o2, k3 : o3 }; // NSNumber 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]; NSNumber *number; number = @'X'; number = @12345; number = @12345ul; number = @12345ll; number = @123.45f; number = @123.45; number = @YES;
http://boboshone.com/blog/2013/04/20/objective-c-literals-nsarray-nsdictionary-nsnumber/