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)
Written by Sergi Gracia
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#