There were some changes introduced to Objective-C by Apple at the 2012 WWDC. If you have not seen the WWDC 2012 video Modern Objective-C
then I would highly recommend you viewing that video which explains the changes introduced. Amongst those changes added were Array Literals
and Dictionary Literals
Basically just like you can create a String Literal
by creating the following:
NSString *name = @"Slim Shady"
Apple introduced Array Literals
and Dictionary Literals
too Following examples are from the Video
Where initially to create an Array the options were:
NSArray *myArray;
myArray = [NSArray array]; // an empty Array
myArray = [NSArray arrayWithObject:anObject]; // an array with a single object
myArray = [NSArray arrayWithObjects: a, b, n, nil]; // array with 3 objects a, b, c
Array Literals allows you to create an Array in the following ways:
myArray = @[ ]; // an empty Array
myArray = @[anObject]; // array with a single object
myArray = @[a, b, c]; // array with 3 objects a, b, c
as you can see using the Literals it is clearer and easier to create the Array. Similarly for NSDictionary
Where initially the options to create a Dictionary were:
NSDictionary *myDict;
myDict = [NSDictionary dictionary]; // empty Dcitionary
myDict = [NSDictionary dictionaryWithObject:object forKey:key];
myDict = [NSDictionary dictionaryWithObjectsAndKeys: object1, key1, object2, key2, nil];
Dictionary Literals allow you to create the dictionary in the following ways:
myDict = @{ }; // empty ditionary
myDict = @{ key:object }; // notice the order of the key first -> key : object
myDict = @{ key1:object1 , key2:object2 };