Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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? What are pros and cons?

like image 417
Centurion Avatar asked Jan 02 '12 11:01

Centurion


People also ask

When should I use user defaults or Core Data?

Core Data is unnecessary for random pieces of unrelated data, but it's a perfect fit for a large, relational data set. The defaults system is ideal for small, random pieces of unrelated data, such as settings or the user's preferences.

Should I use Core Data or realm?

If your project requires encryption or speed, then Realm is an obvious choice. If your project has a complex data model that changes frequently, then Core Data might be a better choice.

How much data can you store in NSUserDefaults?

It appears the limit is the maximum file size for iOS (logically), which is currently 4GB: https://discussions.apple.com/thread/1763096?tstart=0. The precise size of the data is circumscribed by the compiler types (NSData, NSString, etc.) or the files in your asset bundle.

Where does Core Data store data?

The persistent store should be located in the AppData > Library > Application Support directory.


1 Answers

You can refer to Apple's own guide: Implementing Application Preferences

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 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

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.

like image 186
Ankit Srivastava Avatar answered Sep 27 '22 20:09

Ankit Srivastava