使用 mergeModelFromBundles: 和版本控制 (CoreData) [英] Using mergedModelFromBundles: and versioning (CoreData)

查看:14
本文介绍了使用 mergeModelFromBundles: 和版本控制 (CoreData)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 CoreData 中的迁移功能.我遵循了 Apple 文档.我在以下方法中遇到问题:

I'm trying to use the migration feature in CoreData. I've followed the Apple Documentation. I have a problem in the following method:

/**
 Returns the managed object model for the application.
 If the model doesn't already exist, it is created by merging all of the models found in the application bundle.
 */
- (NSManagedObjectModel *)managedObjectModel {

    if (managedObjectModel != nil) {
        return managedObjectModel;
    }
    /* 
     * NSInvalidArgumentException', reason: '*** -[NSCFArray insertObject:atIndex:]: attempt to insert nil'
     * 2010-02-17 16:27:15.338 Patrimoine[3037:207]
     */ 
    managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];    
    return managedObjectModel;
}

http://iphonedevelopment.blogspot.com/2009/09/core-data-migration-problems.html

但我确实选择了 Apple 建议的方法,使用菜单选项添加模型版本".

Yet I did choose the method Apple suggests, by using the menu option "Add Model Version".

你有什么想法吗?

推荐答案

您需要清理您的项目.一旦您版本化"您的模型,Xcode 就会将其移动到一个包(文件夹)中,但它不会删除旧的.然后发生的情况是,下次运行应用程序时,捆绑包中有两个模型的副本;旧的和在妈妈包内的新的.

You need to clean your project. As soon as you "version" your model Xcode moves it into a bundle (folder) but it does not remove the old one. What happens then is that the next time you run your app there are two copies of your model in the bundle; the old one and the new one that is inside of the momd bundle.

Doing a Project -> Clean All 将解决这个问题.

Doing a Project -> Clean All will resolve this issue.

这篇关于使用 mergeModelFromBundles: 和版本控制 (CoreData)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆