NSArray NSDictionary NSNumber using @operator in Xcode 4.4
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Apple LLVM 4.0 new features on Xcode 4.4 (Literals)
我读过一篇这篇文章。
我发现很有技巧。是关于@operator的。
Literals syntax is supported for NSArray, NSDictionary, and NSNumber objects, using the same ‘@’ operator as for NSString literals.
但是,我找不到任何示例代码。
请你用@操作符再解释一下nsnumber、nsarray和nsdictionary好吗?
谢谢。
Mike Ash就这个话题写了一篇很好的文章:
它包括基础知识,以及一些非常酷的实现细节。这至少应该让你开始,如果你有任何其他问题,请留下评论如下!
您可以在LLVM的手册页中找到关于Objective-C文本的新语法。
到目前为止,我看到的最好的文档都在LLVM手册页上。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // integral literals. NSNumber *fortyTwo = @42; // equivalent to [NSNumber numberWithInt:42] NSNumber *fortyTwoUnsigned = @42U; // equivalent to [NSNumber numberWithUnsignedInt:42U] NSNumber *fortyTwoLong = @42L; // equivalent to [NSNumber numberWithLong:42L] NSNumber *fortyTwoLongLong = @42LL; // equivalent to [NSNumber numberWithLongLong:42LL] // floating point literals. NSNumber *piFloat = @3.141592654F; // equivalent to [NSNumber numberWithFloat:3.141592654F] NSNumber *piDouble = @3.1415926535; // equivalent to [NSNumber numberWithDouble:3.1415926535] // BOOL literals. NSNumber *yesNumber = @YES; // equivalent to [NSNumber numberWithBool:YES] NSNumber *noNumber = @NO; // equivalent to [NSNumber numberWithBool:NO] // This creates an NSArray with 3 elements. The comma-separated sub-expressions of an array // literal can be any Objective-C object pointer typed expression. NSArray *array = @[ @"Hello", NSApp, [NSNumber numberWithInt:42] ]; // Immutable dictionary expression: NSDictionary *dictionary = @{ @"name" : NSUserName(), @"date" : [NSDate date], @"processInfo" : [NSProcessInfo processInfo] }; |