Your question isn't quite what you need to ask. A SQLite store in Core Data is merely the backing store for a Core Data object graph. The fact that it's a SQLite database is immaterial to Core Data. So your question is really, "how do I merge two Core Data object graphs into one?"
It kind of depends on what you want to do with the data. One of the rules in Core Data is that you can't have relationships between two objects in different persistent stores. So, if you don't have a need for relationships between objects in Store A and objects in Store B, it's really quite simple. Just add both persistent stores to your NSPersistentStoreCoordinator
, and all the objects from both stores will be available from any managed object context associated with that persistent store coordinator.
If you do need to have relationships between the objects in both stores, or you really just want to have a single store, your best bet would be to create a second NSPersistentStoreCoordinator
and a third, distinct persistent store to hold the merged object graph. You will need to write code to create copies of the objects in a managed object context attached to this second NSPersistentStoreCoordinator
. You'll need to set up the same relationships among the copies that the original objects had, too, but how you go about doing this depends on your data model. If you want to add some more detail to your question, maybe I can give you a better idea of what would be involved.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…