Last Updated: February 25, 2016
·
880
· sergigracia

Literal syntax for dictionary & array creation

Exists different ways to create dictionaries with objective-c.

The standard way to create dictionaries:

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
               someObject, @"anObject",
         @"Hello, World!", @"helloString",
                      @42, @"magicNumber",
                someValue, @"aValue",
                         nil];

Literal syntax for dictionary creation:

NSDictionary *dictionary = @{
              @"anObject" : someObject,
           @"helloString" : @"Hello, World!",
           @"magicNumber" : @42,
                @"aValue" : someValue
};

Literal syntax for array creation:

NSArray *array = @[ @"Value1", @"Value2", @"Value3" ];

Source: Apple (More info here)