简体   繁体   English

我应该使用核心数据来存储一些用户首选项还是将其保存在NSUserDefaults中?

[英]Should I use core data to store some user preferences or save it in NSUserDefaults?

Currently, I'm developing an app that functionality heavily relies upon retrieved JSON data. 目前,我正在开发一个功能严重依赖于检索到的JSON数据的应用程序。 Most of the data I'm planning to save into core data. 我打算将大部分数据保存到核心数据中。 However, not sure do I have to save all user related stuff (settings, favorites, twitter, Facebook and ect.) also in core data, or should I use NSUserDefaults? 但是,我不确定是否必须在核心数据中保存所有与用户相关的内容(设置,收藏夹,推特,Facebook等),还是应该使用NSUserDefaults? What are pros and cons? 什么是利弊?

You can refer to Apple's own guide: Implementing Application Preferences 您可以参考Apple自己的指南: 实现应用程序首选项

you can store the user setting in any way as you want :The choice between NSUserDefaults and Core Data is just between API, where the former was actually designed to handle user preferences. 您可以根据需要以任何方式存储用户设置:NSUserDefaults和Core Data之间的选择就在API之间,其中前者实际上是为处理用户首选项而设计的。

NSUserDefaults and the "built-in settings component" are really one and the same. NSUserDefaults和“内置设置组件”实际上是同一个。 Using the settings app will still store preferences in NSUserDefaults which you access in your app with that API. 使用设置应用程序仍会在NSUserDefaults中存储首选项,您可以使用该API在应用程序中访问这些首选项。

The reason why you might not want to use the built-in settings app would be: It's cumbersome for users to change those settings. 您可能不想使用内置设置应用程序的原因是:用户更改这些设置很麻烦。 If you have settings that users might want to change frequently, you might want to do that inside your app (eg turning music on/off, changing player name). 如果您有用户可能想要经常更改的设置,您可能希望在应用内进行此操作(例如打开/关闭音乐,更改播放器名称)。 Also, since you have full control over your own app, you can have a more flexible GUI than the one Apple provides in Settings.app 此外,由于您可以完全控制自己的应用程序,因此您可以拥有比Apple在Settings.app中提供的GUI更灵活的GUI

As for using Core Data or NSUserDefaults... i would say go with NSUserDefaults as it is much easier to implement and was designed to do this, where as implementing core data will take a lot of effort. 至于使用Core Data或NSUserDefaults ...我会说与NSUserDefaults一起使用,因为它更容易实现,并且旨在实现这一点,因为实现核心数据将需要付出很多努力。

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

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