How to effectively combine 2 core data stores in iOS 7 stores

I am trying to complete my first iOS application and can use some help to efficiently merge the two persistent repositories. Effectively, I mean working with additions and changes without the need to manually analyze the records behind the scenes in order to eventually get one store without duplicates. I foresee constant database updates that we supply to the user, and you will need to update their database without destroying any new records that they could add to the database that we originally provided.

Currently, at startup, the application checks the persistent storage in the "User Documents" folder - name it "Main.sqlite". If he does not find the file, he copies SeedData.sqlite from the application package to Main.sqlite in the user's document directory using the NSFileManager method, -copyItemAtPath: toPath: error :.

Then, if he finds Main.sqlite in the Documents directory, I would like to combine SeedData.sqlite in Main.sqlite. Both stores have the same structure. Merge Criteria: Record SeedData MATCHES Master Record - Do not take any action. Record SeedData NOT FOUND in Main - Add a record SeedData in Main.

The number of records in each repository will be on the order of several thousand.

I know that Sunny dealt with a more complex scenario two years ago. What is an effective way to merge two iOS Core persistent data stores?

I'm wondering if something has changed in the last 2 years that would make the solution even easier and that, if any, will affect the change in iOS 7 to the default log mode from the rollback log to write to Ahead Logging to the solution .

I read Marcus Zarra’s blog and Ray Wenderlich’s guys say that migration is intended to move the database to a new structure, not to move new data between two identical structures - although it seems like Sunny disagrees.

What is the best approach?

+4
source share

Source: https://habr.com/ru/post/1536700/


All Articles