Pregunta

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.

¿Fue útil?

Solución

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

Otros consejos

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];

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"];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top