如何写入plist文件的目标C
问题描述:
我尝试写test.plist文件,该文件被保存在我的支持文件, 这里是我的代码
- (IBAction)acceptAction:(id)sender {
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *pathToFile = [mainBundle pathForResource:@"test" ofType:@"plist"];
NSMutableDictionary *md = [[NSMutableDictionary alloc] initWithContentsOfFile:pathToFile];
[md setValue:@"yes" forKey:@"hasAgree"];
[md writeToFile:pathToFile atomically:YES];
}
- (IBAction)declineAction:(id)sender {
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *pathToFile = [mainBundle pathForResource:@"test" ofType:@"plist"];
NSMutableDictionary *md = [[NSMutableDictionary alloc] initWithContentsOfFile:pathToFile];
NSString *value;
value = [md objectForKey:@"hasAgree"];
NSLog(@"value is %@", value);
}
接受wrtting动作按钮.. 下降对接行动对于阅读它.. 但不工作,有什么建议吗?
答
您不允许在您的软件包目录中编写代码。您必须改用文档目录。搜索一下,你会发现启示。