- (NSMutableDictionary *)updateTemplates:(NSMutableDictionary *)oldTemplates
forSpecType:(NSString *)specType {
// oldTemplates is an NSMutableDictionary pulled from a plist
// specType is used for flexible paths, to eliminate duplicate code
// Make a dict of the parameters object (about to be overwritten)
NSMutableDictionary *parameters = [oldTemplates valueForKeyPath:
[NSString stringWithFormat:@"root.%@.parameters", specType]];
// Dump the new data into the matching object
[oldTemplates setValue:[updateTemplates valueForKeyPath:
[NSString stringWithFormat:@"data.%@", specType]]
forKeyPath:[NSString stringWithFormat:@"root.%@", specType]];
// Put the parameters back, since they don't exist anymore
/* Instant crash, with the debugger claiming something is immutable
* But I just used the exact same method on the line above
* updateTemplates isn't immutable either; it's only when I try to mutate
oldTemplates after putting in updateTemplates -- and only the update
seems to be breaking things -- that I get the exception and crash
*/
[oldTemplates setValue:parameters forKeyPath:
[NSString stringWithFormat:@"root.%@.parameters", specType]];
return oldTemplates;
}
一度に1つのオブジェクトを書き込むループを設定して、updateTemplates.specType
それらの部分だけを置き換えて、パラメーターで何もする必要がないようにすることもできますが、今不変である場合は、書き込みを試みるときになります。また。それは私には何の役にも立たないでしょう。