I need to update / add a key -> value pair in a NSMutableArray.
I would like to add a key with a fix value if the key isn't set already.
I tried the following - but the app is crashing at addObject with a "mutating method sent to immutable object" error:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *bookmarks = [defaults mutableArrayValueForKey:@"bookmarks"];
for (id bookmark in bookmarks) {
if ([bookmark objectForKey:@"type"] == NULL){
[bookmark addObject:@"old" forKey:@"type"];
}
}
[[NSUserDefaults standardUserDefaults] synchronize];
bookmarksis mutable but none of the arrays it contains are mutable.