I wrote this simple code to try out the new Objective-C literal syntax for NSArray
s:
NSArray *array = @[@"foo"];
NSLog(@"%@",
You've got to be compiling with the iOS 6 or OS X 10.8 SDKs -- otherwise Foundation objects don't have the necessary methods for the subscripting bit of the literal syntax.* Specifically in this case, the subscripting expects objectAtIndexedSubscript:
to be implemented by NSArray
, and that's a new method that was created to interact with this compiler feature. The parts of the new syntax that just have to do with object creation should work fine, though -- I don't believe that requires any new methods.
Further reading at http://clang.llvm.org/docs/ObjectiveCLiterals.html
*I base this on a bit of research performed by borrrden: https://stackoverflow.com/a/11407844/603977
I've gotten a lot of upvotes on this answer, which I really feel is founded on borrrden's. Please, if you think my answer is worth an upvote, click through and vote there too.