Reputation: 35050
I want to copy data from one store to an other. Destination persistent store could already have records. Is it any easier way, than manually go though all the records and insert into the new context and save?
Upvotes: 2
Views: 697
Reputation: 70946
If you want to copy all of the data, you can use migratePersistentStore:toURL:options:withType:error:
, which is a method on NSPersistentStoreCoordinator
. This will effectively copy the entire persistent store to a new persistent store file. Some things to be aware of:
If you don't want to copy all of the data, you need to do it "by hand", fetching objects from the old store and creating equivalent objects in the new one.
Upvotes: 4