gpt4 book ai didi

iphone - 如何在 iPhone 中保存 plist 文件中的值?

转载 作者:行者123 更新时间:2023-12-03 20:36:44 26 4
gpt4 key购买 nike

我是 iPhone 开发新手。我使用下面的代码将值添加到 plist,但是在执行代码后检查 plist 时,我没有看到 plist 中保存的任何值。我哪里做错了?我创建的 plist 位于资源文件夹中。

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);

它只给出空值。

最佳答案

资源文件夹不可写。您应该将其保存到文档文件夹中。

关于iphone - 如何在 iPhone 中保存 plist 文件中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2621515/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com