Search code examples
iphonearraysdictionaryplistmutable

Plist array , cannot change dictonaries inside


i have a plist that's at its root an array with dictonaries inside it.

i load a plist from my recourses as an NSMutableArray.

[NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Filters" ofType:@"plist"]]

i store it into nsuserdefault because it has to be persistent between startups.

[[NSUserDefaults standardUserDefaults] setObject:array forKey:@"filters"];

but i can't change the dictonaries in the array because they are not mutable. how can i make them mutable?


Solution

  • You can replace the dictionary by a mutable copy of itself, using the 'mutableCopy' method of NSDictionary.

    [EDIT] Example:

    [ array replaceObjectAtIndex: 42 withObject: [ [ [ array objectAtIndex: 42 ] mutableCopy ] autorelease ] ];