更新&使用新版本的应用程序更改设置 plist 文件
我的应用程序的资源文件夹中有一个默认设置 plist 文件,并且在第一次启动时该文件被复制到文档文件夹中。
在该应用程序的后续版本中,如何将文档中的 plist 设置与任何新键和新键合并?自上一版本以来添加的值(可能是嵌套的)?
我见过一种模式,其中属性实际上在应用程序中创建为 NSDictionary(具有所有默认设置),然后保存在 plist 文件中的当前设置与该字典合并,然后保存在当前 plist 中。
这是一个好方法吗?如果是这样,如何将可能具有多个嵌套值的 NSDictionary 与子数组和子字典合并?
另外,是否建议使用单独的自定义 plist 文件进行设置,还是应该始终使用 NSUserDefaults? NSUserDefaults 是否处理版本控制和更改默认值?
非常感谢,
迈克
I've got a default settings plist file in the resources folder of my app, and on the first launch that gets copied to the documents folder.
In successive versions of the app, how can I merge the plist settings in their documents with any new keys & values (possibly nested) that have been added since the previous version?
I've seen a pattern where properties are actually created as an NSDictionary in the app (with all default settings), and then the current settings saved in the plist file is merged with that dictionary, and that is then saved over the current plist.
Is that a good approach? If so, how do you go about merging NSDictionary's that could have several nested values with sub arrays and sub dictionaries?
Also, is it advised to have a separate custom plist file for settings, or should you always use NSUserDefaults? Does NSUserDefaults handle versioning and changing defaults?
Many thanks,
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我想我已经想出了最好的方法:
Okay I think I've come up with the best way to do it: