UIManagedDocument迁移数据模型 [英] UIManagedDocument migrate data model

查看:101
本文介绍了UIManagedDocument迁移数据模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPhone应用程序,该应用程序使用UIManagedDocument的子类并将其文档存储在iCloud上.

I am working on an iPhone app that uses a subclass of UIManagedDocument and stores its documents on iCloud.

直到我更改了核心数据模型/方案(添加新的模型版本-就像过去几周中的几次),一切都很好. 我添加了一个新属性,并更改了其中一个现有属性的数据类型.

It was all working fine until I changed my core data model / scheme (adding a new model version - like I had several times in the past few weeks). I added a new property and changed the data type of one of the existing properties.

现在,当我运行我的应用程序时,我似乎无法使用UIManagedDocument-openWithCompletionHandler:加载文档. 我可以创建新文档并对其进行读/写. 如果我将数据模型版本改回1,则可以读取现有文档,但不能读取新文档.

Now when I run my app I don't seem to be able to load my documents with UIManagedDocument's -openWithCompletionHandler:. I can create new documents and read/write those. If I change the data model version back 1 then I am able to read the existing docs, but not the new ones.

据我了解,我仅是向数据模型的轻量级迁移,而UIManagedDocument应该能够解决该问题?

From what I understand I am only do lightweight migrations to the data model and UIManagedDocument is supposed to handle that right?

任何建议将不胜感激!

推荐答案

在UIManagedDocument的子类中,您可能想要尝试覆盖ManagedObjectModel,如下所示:

In a subclass of UIManagedDocument you may want to try overriding managedObjectModel like so:

- (NSManagedObjectModel *)managedObjectModel
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"<ModelNameHere>" ofType:@"momd"];
    NSURL *momURL = [NSURL fileURLWithPath:path];
    NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];

    return managedObjectModel;
}

这篇关于UIManagedDocument迁移数据模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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