Ryan Bobrowski
Ryan Bobrowski

Reputation: 2730

iOS - Confused about when to use Core Data in my app

I understand that Core Data is essentially a self-contained local database, but I'm not sure if I should be using it in my app or not. Basically, it would be more for caching purposes if anything, since I retrieve all of my content from a web server database. Regardless, I was wondering if Core Data would be useful is any of these situations:

Scenario #1: I retrieve a list of "items" from the web server and feed them into a table view. This is essentially the first page the user sees. The table can be refreshed to retrieve more results, but existing items likely won't change. Over time this list of items could grow tremendously. Items can be deleted.

Scenario #2: A user has a friends list. This list of friends will stay the same unless he or she adds more friends. I imagine there will be a scenario where a friend deletes their account, in which case the friends list will be altered as well.

Scenario #3: Messages can be attached to items. They can't be edited or deleted, so the only change in state for a list of messages would be if a new message was added. Essentially the same as items, except they can't be deleted.

Upvotes: 0

Views: 158

Answers (1)

nburk
nburk

Reputation: 22731

Actually, for your scenario I would say that you don't need any persistence in your app, but rather fetch your data from the server every time the app starts and just keep it in memory. There are a lot of apps which are doing it this way and this is totally fine behaviour.

However, there are some drawbacks of not using persistence:

  • worse offline experience for your user since they depend on a network connection, so effectively without a connection they can't do anything within your app
  • risk of slow loading

On the plus side we have:

  • using Core Data in your app is a huge implementation overhead (especially if you haven't used it before)
  • after having integrated Core Data, you still have a lot of issues to tackle, first and foremost: data synching between your app and the backend

If you decide to go for persistence, also take a look at alternatives to Core Data like Realm.

Finally, my advice still is to not use Core Data in your situation. However, keep in mind that you can build a version of your app that doesn't use persistence. And then, once you see that your app is well-received and gets more attention, you can still go and add persistence later on.

Upvotes: 1

Related Questions