How do I add multiple objects to same key in an NSMutableDictionary
?
I cannot find the right method. The setObject
method only updates a single object in the key array. The method addObject: forkey:
in the NSMutableDictionary
isn't available and is causing a crash when it is used.
The dictionary is read from a plist
file.
The Dictionary:
temp = {
nickname : score
item 0 = level1;
item 1 = level2;
item 3 = level3;
score
item 0 = 400;
item 1 = 400;
item 3 = 400;
}
Here is the code:
NSMutableDictionary *newDict = [[NSMutableDictionary alloc] init];
str_nickname = [temp objectForKey:@"nickname"];
for (NSString *key in str_nickname){
if ([key isEqualToString:@"level2"]) { //replace object with new name
[newDict setObject:@"new level" forKey:@"nickname"];
} else {
[newDict addObject:key forKey:@"nickname"]; //wont work!!!
}
}
Also I want to update the new score in the new dictionary and have to update this at the corresponding level-object, maybe by the index?