I tried to manipulate an array in an NSMutableDictionary directly:
[[myDictionary objectForKey: @"key"] addObject: object];
This doesn’t work! I even tried type casting:
[(NSMutableArray*)[myDictionary objectForKey: @"key"] addObject: object];
This didn’t work either!
The only way that worked was:
NSMutableArray *array = [myDictionary objectForKey: @"key"];
[array addObject: object];
[myDictionary setObject: array forKey: @"key"]
Is there a way to manipulate the array in the dictionary similar to the first code snippet; i.e. without having to create a new array, manipulating it and then saving it?
The problem was that I wasn’t allocation the array within the NSMutable Dictionary i.e. before adding objects use the following code: