开发者

Copy missing objects from one store to another (with CoreData)

开发者 https://www.devze.com 2023-01-29 03:24 出处:网络
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 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:

  1. Stand up the target store
  2. Stand up the source store
  3. Create a new object in the target store
  4. Reference the object in the source store
  5. Copy the attributes from the source object to the destination object
  6. Repeat 3-5 until all objects are copied over
  7. Save target store

The code to do this is in my Core Data book. You can find the relevant copy code in Chapter 9.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号