8ffbjq
Last Updated: February 25, 2016
·
609
· sergigracia
Sergi2

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)

Say Thanks
Respond
Awesome Job

Da7871ec 1653 11e8 8f5f 0f6902fdcd42
Web System Analyst
·
Ch√Ęteauguay,Quebec, Canada
·
Full Time