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

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

问题描述

我想在CoreData中使用迁移功能。我遵循了苹果文档。我在以下方法中有问题:

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 will resolve this issue.

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

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