写入 .plist 文件

发布于 2024-08-28 07:39:24 字数 514 浏览 1 评论 0原文

我有一个 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

装迷糊 2024-09-04 07:39:24

您没有正确初始化路径。

如果“myprefs.plist”位于项目的资源文件夹内,则按如下方式初始化:

NSString *filePath = [[NSBundle mainBundle]pathForResource:@"myprefs" ofType:@"plist"];

如果它在计算机的其他位置,请指定整个路径

You did not initialize the path properly.

If "myprefs.plist" is inside the resources folder of your project then initialize like this:

NSString *filePath = [[NSBundle mainBundle]pathForResource:@"myprefs" ofType:@"plist"];

If its somewhere else in your computer, specify the whole path

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文