This the snippet of code where I get an error:
//sourceArray is a NSMutablearray
NSMutableDictionary *dayOfWeekDictionary= [sourceArray objectAtIndex:indexpath.row];
[dayOfWeekDictionary setObject:[NSNumber numberWithBool:YES] forKey:@"isSelected"];//line 2
What I’ve come to know from googling is that there is some stuff in assigning immutable object into mutable object.
I get an error at line 2. Any suggestions?
If
[sourceArray objectAtIndex:indexpath.row]returns an immutable dictionary, simply assigning it to a variable of typeNSMutableDictionary *doesn’t automatically convert it to a mutable dictionary. You could write this instead:By using
+[NSMutableDictionary dictionaryWithDictionary:], you get a mutable dictionary based on another dictionary (which can be either mutable or immutable). Note that you do not own this dictionary, hence you don’t have to release it. Also note that this is not the same dictionary object as the one stored in the array. If you need both the array anddayOfWeekDictionaryto be the same dictionary, then you should add a mutable dictionary to the array.