What do I have to do to get Core Data to automatically migrate models?

前端 未结 10 1806
感情败类
感情败类 2020-11-27 09:14

I have read the documentation about automatic /lightweight migration for Core Data models - but I am having problems implementing it.

As I understand it the applicat

相关标签:
10条回答
  • 2020-11-27 09:33

    Grouchal's answer is perfect...but if you are still having the "Can't merge models with two different entities xxx" even after cleaning up the build several times...Your might have issues with how the managedObjectModel is being loaded...take at look at this one...which helped me fix it..

    core data migration problems

    0 讨论(0)
  • 2020-11-27 09:35

    iOS 4.0+

    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"model" withExtension:@"momd"];
    managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    
    0 讨论(0)
  • 2020-11-27 09:37

    Minor edit to @Grouchal's awesome instructions above for Xcode version 5:

    Old: 2. Select the Design Menu at the top - then Data Model - then choose Add Model Version

    Version 5+: 2. Select the Editor menu, then Add Model Version…, type your Version name and Based on model (select your original model from the list)

    0 讨论(0)
  • 2020-11-27 09:39

    This was incredibly helpful. The Apple documentation was -- as usual -- woefully incomplete. I recommend doing a clean build, as I ran into an error "Can't merge models with two different entities xxx" when I first ran after making these changes. The clean build fixed it up.

    0 讨论(0)
提交回复
热议问题