2

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.

jscs
  • 63,694
  • 13
  • 151
  • 195
Alan
  • 9,331
  • 14
  • 52
  • 97
  • ["Apple committed a *new (as of 2012) patch* to the llvm project adding support for new Objective-C *literal syntax* for NSArray, NSDictionary and NSNumber .."](http://joris.kluivers.nl/blog/2012/03/13/new-objectivec-literal-syntax/) – user2864740 Oct 22 '13 at 18:51
  • http://stackoverflow.com/questions/9693647/is-there-some-literal-dictionary-or-array-syntax-in-objective-c – user2864740 Oct 22 '13 at 18:52

3 Answers3

5

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

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
2

It mean you are assigning to object an array Like below:-

NSArray*arr=[[NSArray alloc]initWithObject:URL];

Samething you can write like this as well:-

NSArray*arr=@[URL];

Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
0

Create an array with one object: URL.

You can create arrays and dictionaries using the @ symbol in objective c as follows:

NSDictionary *dict = @{
 @"string key":@"string value",
 (id)objectKey:(id)objectValue
};

NSArray *arr = @[(id)objectValue,@"string value"];
Adam Jenkins
  • 51,445
  • 11
  • 72
  • 100