• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 设置动态值后如何将数据保存到ios中的plist中?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 09:12:16 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

<plist version="1.0">
    <dict>
            <key>InfoValue</key>
            <string>false</string>
            <key>AudioValue</key>
            <string>true</string>
            <key>VideoValue</key>
            <string>true</string>
            <key>DescValue</key>
            <string>true</string>
            <key>LinkValue</key>
            <string>true</string>
   </dict>
</plist>

这是 plist 文件,我想动态更改 InfoValue。在我的代码中,我正在使用类似

settingsPath=[[NSBundle mainBundle] pathForResource"SettingsValue" ofType"plist"];
settingsItem = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];

[settingsItem setObject"false" forKey"InfoValue"];

在这之后

[settingsItem writeToFile:settingsPath atomically:YES];

但它没有将数据保存到 plist 文件中。而不是我收到以下错误:

-[NSConcreteValue getFileSystemRepresentation:maxLength:]: unrecognized selector sent to instance 0x8fad490
2013-02-27 10:26:44.479 vCamView[1577:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
 reason: '-[NSConcreteValue getFileSystemRepresentation:maxLength:]: unrecognized selector sent to instance 0x8fad490'
*** First throw call stack:
(0x33dc012 0x2944e7e 0x34674bd 0x33cbbbc 0x33cb94e 0x2354915 0x23548b9 0x2354872 
   0x235468f 0x1e207 0x2958705 0x188f920 0x188f8b8 0x1950671 0x1950bcf 0x1a90747 
   0x2342e83 0x339b376 0x339ae06 0x3382a82 0x3381f44 0x3381e1b 0x376f7e3 0x376f668 
   0x188c65c 0x27e2 0x2715)



Best Answer-推荐答案


您不能修改包内的文件。它是只读的。尝试将 plist 保存在 DocumentDirectory

    NSString *directoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES)objectAtIndex:0];
    NSString *filePath = [directoryPath stringByAppendingPathComponent"SettingsValue.plist"];

   // Read from document directory
    settingsItem = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath]; 

    // update the dictionary
    [settingsItem setObject"false" forKey"InfoValue"];

   // write back to file  
    [settingsItem writeToFile:filePath atomically:YES];

关于ios - 设置动态值后如何将数据保存到ios中的plist中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15104646/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap