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