Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why might I want 2 or more Core Data models?

Tags:

ios

core-data

I am curious to know who uses multiple core data models and why, what are the benefits, I am developing an application which I think I could benefit from multiple models, but I'm unsure of other benefits.

My up and coming app will be for iPad and another version for iPhone, the iPad has 3 main contents, the iPhone only has one which is also on iPad, so by isolating this into a different core data model maybe maintaining changes of that model across my two apps will be easier.

Although I do have a couple of entities which I would need in both, so I could just copy them over or have one big model.

Any suggestions ?

Anyway this isn't of course a common situation, what other scenarios might lead you to create multiple Core Data models ?

like image 724
Daniel Avatar asked Apr 29 '12 18:04

Daniel


1 Answers

Sometimes it makes sense to keep different kinds of data in different stores. For example, an app that works like a product catalog might have one store that's a product database, and another that keeps track of the user's favorites, current orders, and history. That makes it relatively easy to update the product database without affecting the user's data, and to back up the user's data without having to copy the entire product database.

Another scenario where you'd use multiple stores is to store the same type of data. Document-based applications, for example, will generally create a separate store for each document -- the store may be the document.

Update: What I wrote above addresses using separate stores, but you asked about using separate models. Core Data will actually let you define separate models and then merge them all together at runtime for use in the same store (or multiple stores, for that matter). So, just to be clear, a model defines entities and the relationships between them. A store is the place where the data is actually saved using the schema defined in the model. You might break a complicated model up into several smaller models just to keep things simple and to aid in migrating your data as you modify your models over time, or you might use multiple models and keep them separate because you plan on using different stores that contain different types of data, as described above.

like image 149
Caleb Avatar answered Nov 03 '22 03:11

Caleb