objective-cnsarrayobjective-c-literals

What does @[] mean?


I am looking at a tutorial and I am not sure what the line of code means:

self.objectsToShare = @[URL];

URL is an NSURL, and self.objectsToShare is an NSArray.


Solution

  • It is a shorthand syntax for array creation.

    Instead of:

    [NSArray arrayWithObjects:&URL count:1];
    

    More information here: http://clang.llvm.org/docs/ObjectiveCLiterals.html