序列化 plist
我已经尝试了所描述的各种技术来序列化我需要的 plist,以保存用户的收藏夹。
有些人还说最好将该数据保存到“用户默认值”文件中。
哪种技术更好以及它们是如何序列化的。我有这段代码
[plistArray writeToFile:filepath atomically: YES];
,它将对象添加到数组中,但似乎无法保存 plist 编辑。
问候
I have tried the various techniques described to serialize a plist I need in order to save the favorites of the user.
Some people also say it is better to save that data into the "user defaults" file.
Which is the better technique and how are they serialized. I have this code
[plistArray writeToFile:filepath atomically: YES];
which adds the object to the array, but cant seem to save the plist edits.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你想保存首选项,那么合适的方法是使用 NSUserDefaults 机制,因为它会为你节省大量时间和麻烦。
但是,如果您使用 PLIST 作为持久存储在 NSDictionary 中的数据的方法,那么我认为使用 writeToFile 方法是合适的。
If you want to save preferences, then the appropriate method is to use the NSUserDefaults mechanism as it will save you a hell of a lot of time and hassle.
However, if you're using a PLIST as a means of persisting data that's stored in say, an NSDictionary, then I think it would be appropriate to use the
writeToFile
approach.如果您想保存任何类型的首选项,只需将它们存储在用户默认字典中即可。这是唯一正确的方法 - 此外,您还要确保,如果用户同步其手机,iTunes 会对其进行备份。
If you want to save preferences of any kind, just store them in the user defaults dictionary. That's the only correct way – and additionally you make sure, that iTunes will back it up, if the user syncs its phone.