Мое приложение iphone записывает пары ключ-значение в словарь в файле plist. Я в основном сохраняю счет пользователя, когда он играет в игру. Это все прекрасно, но каждый раз, когда я запускаю приложение и получаю новые оценки, новые значения сохраняются поверх старых. Как добавить информацию в список каждый раз, когда пользователь обращается к приложению, а не переписывать файл? Я хочу сохранить все оценки, а не только самые последние.
код:
-(void)recordValues:(id)sender {
//read "propertyList.plist" from application bundle
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path
stringByAppendingPathComponent:@"propertyList.plist"];
dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:finalPath];
//create an NSNumber object containing the
//float value userScore and add it as 'score' to the dictionary.
NSNumber *number=[NSNumber numberWithFloat:userScore];
[dictionary setObject:number forKey:@"score"];
//dump the contents of the dictionary to the console
for (id key in dictionary) {
NSLog(@"memory: key=%@, value=%@", key, [dictionary
objectForKey:key]);
}
//write xml representation of dictionary to a file
[dictionary writeToFile:@"/Users/rthomas/Sites/propertyList.plist" atomically:NO];
}