CoreData with multiple stores: configuration woes

前端 未结 1 1990
青春惊慌失措
青春惊慌失措 2020-12-23 15:15

I have an iOS project with a large, preloaded database and a small user database (both CoreData SQLite stores). Previous questions have suggested using configurations to con

相关标签:
1条回答
  • 2020-12-23 16:01

    Have you tried having both configurations defined in the same model (i.e. same momd)? You can do this easily by selecting "Editor->Add Configuration" while editing one of your data models. Drag entities for UserData and ItemData into the appropriate configuration. The configuration specified this way is what Core Data respects; it's not about the file/URL name. Once you've done the above, then simplify your _managedObjectModel above to look for the single momd file/URL whenever it is called.

    Alternatively, if you do decide to keep two separate momd files, make sure you've actually defined your models in the Configurations named "UserData" and "ItemData" respectively in their model definition files.

    My initial suggestion is to keep one model file. Unless there is a reason these configurations cannot reside in the same object model, it doesn't make sense to complicate things with multiple files. I think it would be quite difficult to finesse Core Data into doing what you are trying to do above. Try to simplify the modeling part of your code.

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