Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data with multiple sqlite files

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.

like image 325
Egil Avatar asked Dec 21 '25 22:12

Egil


1 Answers

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.

like image 117
bbum Avatar answered Dec 23 '25 21:12

bbum