iOSAppGuy
iOSAppGuy

Reputation: 633

Should Core Data be used in only specific types of data models or can it always be used?

I'm building iOS apps. Many books talk about the power of using Core Data. So far I've pretty much been avoiding Core Data because it never seems to apply to the types of apps I create. I'm not sure if this is true or I'm not realizing what it all about.

For example, I built a video poker app for iPad. I've separated out the app according the MVC paradigm. My model is where I create my cards. Since I'm keeping track of the cards that are being being played and discarded, I set up my Model as a singleton and my View Controller asks the models for the cards it needs.

Then I'm like, maybe I could rebuild this type of app to better understand how Core Data works. I'm thinking instead of a singleton model, my View Controller would reference the Core Data model. I know that Core Data is the model of the MVC design pattern. Core Data stores objects. My cards are objects. This seems like this applies. I should be able to rebuild my app using Core Data. Right?

Then everything I read about Core Data is like this: Assume you have an author and they've written several books. There is a relationship between author and book and book to author. Core Data allows me to queue an author and it will allow me to access his books or manipulate that data.

In my example - creating / accessing card objects - I'm not dealing with the author-book type relationship. Since I'm not dealing with that, should I just assume Core Data shouldn't / couldn't be used in an app that I'm describing?

Must I have a relationship like author to book to use Core Data? Or are those examples just showcasing a complex feature built into Core Data?

I'm not in a rush to rebuild my app using Core Data, it works fine as is. I'm just looking for some direction as to how to better understand when and why I would want to / need to use Core Data.

Upvotes: 0

Views: 227

Answers (1)

bandejapaisa
bandejapaisa

Reputation: 26972

You would use core data if you need to persist data. It's a ready made persistence and object management framework. You don't need to worry about the details of how your data is stored or retrieved.

Even if you only have one Entity (your Card). It's still fine to use core data. You don't have to have relationships if they are not relevant for your case. In your particular example, you might want to keep a track of every poker game played, the hands that each player had, the cards dealt. This might be used for post game analysis - or to see a history, or to replay a game automatically. You could store all this very easily in Core Data.

Some examples that I use core data for:

I have an app Flickr Gallery PRO. I keep a history of all photos viewed and all photo streams viewed. I store these using Core Data. If I didn't use Core Data for this, I would have to roll out my own persistence mechanism.

Another app of mine, Stats for Flurry, again I use Core Data. Here the intention is for offline use and to sync with Flurry servers. I call flurry servers to download data, and persist it to Core Data.

I've worked on apps for large newspapers. Again we used Core Data so that the app would sync to the servers, download the latest news and store it in Core Data so the user could read it later offline.

Upvotes: 4

Related Questions