Core Data with multiple sqlite files

◇◆丶佛笑我妖孽 提交于 2020-01-02 08:42:11

问题


How may I use Core Data with multiple SQLite files?

Each file contains the same structures but the data is retrieved from different locations.
I want to be able to switch between these sqlite files at runtime based on application settings.


回答1:


Sure; just point the persistent store coordinator (NSPersistentStoreCoordinator) at the different databases, as needed.

Persistent store coordinators support addition and removal of stores. On removal, you want to make sure that there are no unsaved changes in memory (obviously) and, in general, that you will not be messing with any entities fetched from the removed store after removal.

Be careful, though, as Core Data does not support relationships where the objects at either end are in different stores.



来源:https://stackoverflow.com/questions/6323203/core-data-with-multiple-sqlite-files

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