简体   繁体   English

iPhone SDK:NSUserDefaults还是NSDictionary?

[英]iPhone SDK: NSUserDefaults or NSDictionary?

Compare the following: 比较以下内容:

  • using NSUserDefaults saving it with synchronize 使用NSUserDefaults通过同步保存它
  • using NSDictionary saving it with writeToFile in the app Documents folder 使用NSDictionary使用writeToFile将其保存在应用程序Documents文件夹中

What are the differences? 有什么区别? Personally, I prefer to mantain different NSDictionary organized by topic rather than use a single NSUserDefaults. 就个人而言,我更喜欢按主题组织不同的NSDictionary,而不是使用单个NSUserDefaults。

Am I thinking something wrong? 我在想什么问题吗? Thanks 谢谢

It depends on the kind and amount of data that you want to save and how you want to access this data. 这取决于要保存的数据的种类和数量以及如何访问此数据。 Property list files in the documents directory can be deserialized on demand while the user preferences are usually read early after launching the app. 可以按需反序列化documents目录中的属性列表文件,而用户首选项通常在启动该应用程序后尽早读取。 They also contain keys owned by the system. 它们还包含系统拥有的密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM