我正在尝试修改 plist 并保存更改,但它不起作用:
这是我的代码:
NSString *myPath = [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"];
NSMutableDictionary *plistDict;
NSMutableArray *array = [[NSMutableArray alloc]initWithArray:[plistDict objectForKey:@"$objects"]];
for (int i =0 ; i <array.count; i++)
{
if ([[array objectAtIndex:i] isKindOfClass:[NSString class]])
{
if ([[array objectAtIndex:i] isEqualToString:@"myString"])
{
[[plistDict objectForKey:@"$objects"]replaceObjectAtIndex:i withObject:@"newString"];
}
}
}
NSString *root = @"/Users/myUser/Desktop/newPlist.plist";
[plistDict writeToFile:root atomically:YES];
内容的字典已被修改,我没有任何错误,但该文件从未在路径中创建。你们中的任何人都知道我在做什么错吗?或者我该如何解决?