Fairly new to this. I am trying to add some value/keys to an array that already has value/keys.
The itemsArray contains the json and is derived from the variable json which is a parameter passed to the method from a rest api call.
This is the code I am using and it aborts (at [i setobject] with [__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'
NSMutableDictionary *itemsArray = [json objectForKey:@"items"];
for ( NSMutableDictionary *i in itemsArray) {
[i setObject:@"FirstValue" forKey:@"parents"];
}
All this should do is add in the key called parents for each item in the dictionary.
Now if I hard code the value/keys to the mutable dictionary itemsArray - it works fine. Its just when I use the variable json which is passed as a parameter and obtained from a call to a rest api. So the issue is likely that itemsArray contains a immutable json object even though itemsArray is mutable.
The question I have is how do I make the json object mutable (assuming that will cure it) so it will work. ?