写入 .plist 文件
我有一个 .plist,其中有 2 个键值。它是字典类型。我正在尝试将值写入关键值之一。下面的代码有什么问题?我还尝试使用“Array”类型。该选项也不起作用。我怎样才能使用 Dictionary & 让它工作?还数组?有人有工作代码示例吗?谢谢。我将不胜感激任何帮助。
NSString *filePath = @"myprefs.plist";
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
[plistDict setValue:@"[电子邮件受保护]" forKey:@"电子邮件”];
[plistDict writeToFile:filePath 原子地:是];
I have a .plist with 2 key values in it. It is of type Dictionary. I am trying to write value to one of the key values. What's wrong with the code below? I also tried using type "Array". That option also does not work. How can I get it to work using Dictionary & also Array? Anyone has working code example? Thanks. I would appreciate any help.
NSString *filePath = @"myprefs.plist";
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
[plistDict setValue:@"[email protected]" forKey:@"Email"];
[plistDict writeToFile:filePath atomically: YES];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有正确初始化路径。
如果“myprefs.plist”位于项目的资源文件夹内,则按如下方式初始化:
如果它在计算机的其他位置,请指定整个路径
You did not initialize the path properly.
If "myprefs.plist" is inside the resources folder of your project then initialize like this:
If its somewhere else in your computer, specify the whole path