3

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?

1

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.

3

To answer the last question, it's not a good idea to store large amounts of data in NSUserDeafaults.

NSUserDefaults is not made for parge chunks of data. It's a singleton, and all of it's data is loaded at all times, also you can't easily have multi-threading support with NSUserDefaults.

Using Core Data would be better than NSUserDefaults.

What I would suggest in your situation is to cache data that is accessed often. This way, you provide a more responsive experience without taking up a bunch of memory on the user's device.

  • Thank you for the answer. I'll look into how to cache data in iOS/Swift. Again thanks, helps me improve as a programmer. – Lorenzo von Matterhorn Dec 9 '15 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.