Why might I want 2 or more Core Data models?

前端 未结 2 920

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.

提交回复
热议问题