Using two different Core Data Models in the same iPhone app. How can I do it?

ⅰ亾dé卋堺 提交于 2019-12-05 20:49:33

You can do it two different ways:

  • You can set up a separate entire core data stack, effectively just copying the template code you already have in your AppDelegate.

  • You can add the second Core Data sqlite file into the existing core data stack. This will let you access both Entities (not tables, this is an object graph not a database) in the same stack. To do that you add a second -addPersistentStore... call in your -persistentStoreCoordinator method and make sure your -managedObjectModel method is doing a merge of the models in your bundle.

Update

Set it up anywhere you want. You can set it up in the AppDelegate and then do a dependency injection and push down the second stack to whoever needs reference to it.

Generally I would not create the stack in the UIViewController as it is not its responsibility.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!