iOS Development – Core Data vs. NSUserDefaults

data structuresiosiphone

I am creating an App where users can search items from an external API. If the users likes an item they can store them into their personal "favourites item list".

My question is, is it a good practice to save this data as part of core data or NSUserDefault. Currently the data is stored within my database. Every time the user tries to access their favourites list I have to make an HTTP command to retrieve the data from the database.

This process is slow, so I want to save the favourites list data into core data or NSUserDefault. Is this a good approach.

Keeping in mind that the list could grow fast, depends on the users.

Is it a good idea to store large amount of data in core data or UserDefault?

Best Answer

Is it a good idea to store large amount of data in core data or UserDefault.

I'd vote for "leave it server side".

One advantage to storing the data server side is that you get the same favorites whether you're connecting from your phone or tablet.

When I used to program for mobile, I tended to treat the entire device as a Presentation layer. For example, if you had 1,000 "favorites", I might send only a couple hundred names of favorites in the initial HTTP call.

As you scrolled, I'd send down more names. I wouldn't send down the details until you either stopped scrolling for a second or you actually selected a single favorite to view. (If you stopped scrolling I might download the details for the dozen or so favorites currently visible on the screen).

Of course, this only works if you have a reliable network connection. If you have to function offline, then your only choice is to cache the data locally, probably in core data.

Related Topic