是否可以防止删除未设置的属性(在 plist 中)?
我的代码:
- (NSString*)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;
}
- (void)store {
if ([[NSFileManager defaultManager] fileExistsAtPath:[self dataFilePath]]) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:textField.text forKey:@"text"];
[dict setValue:textField2.text forKey:@"text2"];
[dict writeToFile:[[self dataFilePath] stringByAppendingPathComponent:fileName] atomically:NO];
}
}
- (void)load {
if ([[NSFileManager defaultManager] fileExistsAtPath:[self dataFilePath]]) {
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:[[self dataFilePath] stringByAppendingPathComponent:fileName]];
textField.text = [dict objectForKey:@"text"];
textField2.text = [dict objectForKey:@"text2"];
}
}
如果我注释掉该行[dict setValue:textField2.text forKey:@"text2"];
,该属性将被删除。是否可以说覆盖属性,但保持存在?
迈克