Why might I want 2 or more Core Data models?

前端 未结 2 912

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\

相关标签:
2条回答
  • 2021-02-14 12:56

    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.

    0 讨论(0)
  • 2021-02-14 13:01

    I'd recommend using just 1 core data model. If you separate them, you won't be able to use a lot of the features of Core Data, such as relationships (between objects in the data store) etc. Even if you don't see the need right now, you may come up with an idea to add to the app later that needs it.

    You could still use the same core data model for both iPad and iPhone, just ignore the parts you're not using the iPhone (until you get feature requests to add the missing parts, which you very likely will). Then you'll be all set and already have the data available.

    Only in extreme cases would it be worth using a separate data model, for example, if you were going to download an existing data set that was read only etc. You might separate the read only data set from the users settings/data etc.

    Good luck with the app!

    0 讨论(0)
提交回复
热议问题