Search code examples
ioscore-datacore-data-migration

How the Core Data Migration will work for two projects?


I'm working on an app which using core data (one app is already live on the AppStore). OK, now I want to make it fully functional for iOS8 and client also asked me to make a good change in UI and its structure so I started a complete new project and decided to code it my self. Everything works fine, then client emailed me and confirm that, new version of app should store & fetch existing values from the database if existing app will get update. I feel bad here.

I know core data migration is possible ( I read this too, but there's some glitches in my mind about this concept.

  • As I told, I started a new project though is it possible to add a new version of the model?
  • Our entities and attributes names are not same. I named it the way I want.
  • Our model name is same. e.g. Somename.xcdatamodel
  • My app will update to the existing app on the AppStore.

How I can migrate the existing core data database to the new one?

  • Is this possible? How?

Any suggestions and help on this would be appreciated.

Note: I read this question, Core Data Migration: How to delete the Core Data stack? and found that there's no issue if I delete the previous model? What you suggest?


Solution

  • If you need to migrate and keep the existing data, you should read more about writing custom policy Core Data Versioning Guide. Read this guide completely to get to know which category your app migration falls in. 1. Lightweight migration. 2. Or you have to write your own custom policy.

    As far as i can tell from the details you provided it looks like it might be a lightweight migration for which you do not have to do anything you can just add a new version to xcdatamodel and mapping models. If not then you have to write your own custom policy and mapping models.

    Also make sure you test upgrade properly.