I’m beginning Objective-C (coming from Python)
I need to create and initialize a simple dictionary.
In Python I was used to do:
arr = [
{'fieldX': value1, 'fieldY': value2},
{'fieldX': value3, 'fieldY': value3},
]
Here is what I’m doing in Objective-C
NSArray *arr = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
value1, @"fieldX", value2, @"fieldY"
, nil]
, [NSDictionary dictionaryWithObjectsAndKeys:
value3, @"fieldX", value4, @"fieldY"
, nil]
, nil
];
Isn’t there a simpler way to initialize this array of dictionaries ?
since ios6 you can use literals
more info: http://clang.llvm.org/docs/ObjectiveCLiterals.html