如何在iphone的plist文件中保存值? [英] How to save a value in a plist file in iphone?
本文介绍了如何在iphone的plist文件中保存值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是iphone开发的新手。我使用下面的代码将值添加到plist但是在执行代码后检查plist时我没有看到plist中保存的任何值。我哪里出错了?请帮帮我。我创建的plist是在资源文件夹中。谢谢。
I am new to iphone development.I am using the below code to add the value to the plist but when check the plist after executing the code i dont see any value saved in the plist.Where do i go wrong? please help me out.The plist i have created is in the resource folder.Thanks.
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"regvalue.plist"];
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:finalPath];
[plistDict setValue:@"hello" forKey:@"choice"];
[plistDict writeToFile:finalPath atomically: YES];
用于检索值
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"regvalue.plist"];
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:finalPath];
NSString *value;
value = [plistDict objectForKey:@"choice"];
NSLog(@"the value is %@",value);
它只给出空值。请帮帮我。谢谢。
It gives only null value.Please help me out.Thanks.
推荐答案
资源文件夹不可写。您应该将其保存到文档文件夹中。
The resources folder is not writeable. You should save it into the documents folder.
这篇关于如何在iphone的plist文件中保存值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文