I need to be able to be able to set the values of nested NSDictionary and NSArray. For example:
dictionary array dictionary key1 value1
What is the easiest way to get to key1 and set value1? setValueForKeyPath obviously doesn't work with and array.
Using Objective-C's Object Subscripting.
Imagine the following nested dictionaries and arrays:
dictionaryA => arrayB => dictionaryC
arrayB is stored under @"arrayKey" in dictionaryA, and
dictionaryC is stored at index dictionary_index into arrayB.value1 for @"key1";To set key1, you need to do:
(NSDictionary*)((NSArray*)(dictionaryA[@"arrayKey"])[dictionary_index])[@"key1"] = value1;
See the section Object Subscripting in Clang 3.3 documentation: OBJECTIVE-C LITERALS for more informations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With