i am in love with core data in the few last months,开发者_运维知识库 and used it to save data in my app including the user settings. it works great but i am afraid that i will have problem with future updates.
i know 3 ways to store preferences in my app - 1. core data. 2. NSUserDefaults. 3. using the build in setting component.
love to understand the pros and cons of this approaches.
thanks shani
Edit note: My previous link,
Implementing Application Preferences, is broken. The rest of this reply should still apply. However, you can now also store data in iCloud in a manner that's similar to (but separate from)NSUserDefaults
.
You can refer to Apple's own guide: About Preferences and Settings
First, you can store settings however you want: It's just user data. The choice between NSUserDefaults and Core Data is just between API, where the former is designed specifically to handle user preferences. But you could (technically) use INI files, if you absolutely wanted to (but don't!). So there are more than 3 ways to do it.
Second, NSUserDefaults and the "built-in settings component" are really one and the same. Using the settings app will still store preferences in NSUserDefaults which you access in your app with that 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 (e.g. 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
But it's really a question of GUI, not how settings are stored.
As for using Core Data or NSUserDefaults... well, as I said, one is designed specifically for user preferences, the other for row-based user data. NSUserDefaults lets you have default settings, is trivial to add new settings to and supports the built-in settings system. It's also quite simple: It just loads a property list. Core Data on the other hand requires the whole persistent store and managed object context stack.
To summarize: Use NSUserDefaults for settings, and choose between the built-in settings app and having your own control panel based on how often settings must be changed and your specific needs.
精彩评论