MSU_Bulldog MSU_Bulldog - 1 year ago 107
iOS Question

iOS: Should I use Core Data or NSUserDefaults?


I have an app that retrieves a list of restaurants from a database, each have an individual array of basic information about them (hours, name, address, etc). I would like to retrieve that information from the server on the apps first load, but then have it stored within the app itself, with either NSUserDefaults or Core Data, since the information is unlikely to change. The max number of restaurants I would be storing is about 25, is that a small enough data collection to use NSUserDefaults?

I have looked at similar questions with storing data with over 1,000 records, but I am only storing a small array.


NSUserDefaults is much easier to use than Core Data, so if possible I would like to avoid using Core Data. In my case, will there be a performance problem if I am storing my list of restaurants in NSUserDefaults instead of Core Data?

Answer Source

Depends on the

  • size
  • structure of data
  • requirements re integrity of the data

Just an Array of 10 or 20 "restaruants" I would certainly store in NSUserDefaults. But only when I am sure that this will never become more complex. Because when you later extend your model but started off with NSUserData then you may remain with NSUserDefaults just because you avoid migrating it to Core Data during the upgrade of an installed app.

So for more complex structures including references and when you have further plans with your app towards more functionality that may require more entities, then you should go for Core Data from start.

BTW, it is not that complicated as you may think.

However, instead of abusing NSUserDefaults, you could simply write an NSArray to file using -writeToFile:atomically: and -initWithContentsOfFile: to read them in.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download