Plist只是不保存自己...
我不明白我在这里做错了什么。请帮忙。
NSString *factorsFile = [[NSBundle mainBundle]pathForResource:@"factors" ofType:@"plist"];
NSMutableArray *factorsArray = [NSMutableArray arrayWithContentsOfFile:factorsFile];
NSMutableDictionary *dictFactor = [NSMutableDictionary dictionary];
[dictFactor setObject:self.nameField.text forKey:@"Factor"];
[dictFactor setObject:self.rankField.text forKey:@"Rank"];
NSLog(@"%@",dictFactor);
[factorsArray addObject:dictFactor];
NSLog(@"%@",factorsArray);
if([factorsArray writeToFile:factorsFile atomically:YES]){
NSLog(@"lalal");
}
此代码能够进入最后一个if循环但是plist保持不变......为什么?
答案 0 :(得分:2)
因为您无法在应用包中编写/修改文件。
您可以为表达式"ios plist write to bundle unchanged"执行Google搜索,然后您可以查看前四个结果。它们都是相同/重复的StackOverflow问题:
plist writing data inside dictionary
write into plist file using NSDictionary object