Copy missing objects from one store to another (with CoreData)
I have a sqlite db in my project resources folder and I want to copy all objects of an entity of that store into the users db store when they are missing.
I googled already a lot and many people talk about NSMigra开发者_JS百科tionManager, direct SQLite3-statements and on and on. But what is the best approach to do this? Is there a way to do this with CoreData directly? I would be very thankful if you could give me a code snippet which explains your solution.
THANKS Phil
Yes this can be done directly. The steps are:
- Stand up the target store
- Stand up the source store
- Create a new object in the target store
- Reference the object in the source store
- Copy the attributes from the source object to the destination object
- Repeat 3-5 until all objects are copied over
- Save target store
The code to do this is in my Core Data book. You can find the relevant copy code in Chapter 9.
精彩评论