如何用信息更新现有的 plist?我有带字符串的简单字典。这是我的保存方法:
#define DOCUMENTS [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
- (IBAction)saveData:(id)sender {
NSMutableDictionary *data = [NSMutableDictionarydictionaryWithObjects:@[self.textFieldOne.text, self.textFieldTwo.text, self.textFieldThree.text] forKeys:@[@"Key1", @"Key2", @"Key3"]];
NSError *error = nil;
NSData *dataToPlist = [NSPropertyListSerialization dataWithPropertyList:data format:NSPropertyListXMLFormat_v1_0 options:0 error:&error];
NSString *path = [DOCUMENTS stringByAppendingPathComponent:@"userData.plist"];
[dataToPlist writeToFile:path atomically:YES];
}
所以,当我从 Class 1 调用这个方法时没问题,但是当我想用 Class 2 的其他信息更新这个 plist 时——它会用新信息覆盖旧信息。我应该怎么做才能用其他类的新信息更新现有的 plist?