I have a property list which I read into an NSDictionary, from which I would like to create a mutable copy into an NSMutableDictionary to edit the contents and - later be able to reset the mutable dictionary by copying back the original contents.
NSDictionary *defaultRows;
NSMutableDictionary *rows;
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Config" ofType:@"plist"];
defaultRows = [[[NSDictionary alloc] initWithContentsOfFile: plistPath] objectForKey:@"rows"];
This is how I try to create a copy of the original dictionary (according to Apple's recommendation):
rows = [NSMutableDictionary dictionaryWithDictionary: defaultRows];
When I try to change the contents of the dictionary rows with:
[[[rows objectForKey:self.company.coaTypeCode] objectForKey:statementType] removeObjectsAtIndexes:rowsToDelete];
I get the runtime error *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object'
.
I have read the article here, but wonder if there is a more elegant method to implement a deep copy?