【发布时间】:2012-03-19 13:24:13
【问题描述】:
我在斯坦福 CS193P 课程关于使用 iOS 5 的新类 UIManagedDocument 之后开始在我的应用程序中使用 CoreData。该方法本身非常简单,但我无法理解如何处理我不断进行的模型修改。这就是我实例化 UIManagedDocument 对象的方式(在 appDelegate 中,以便其他所有类都可以使用它):
if (!self.database) {
NSURL *url=[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:@"AppName"];
UIManagedDocument *doc = [[UIManagedDocument alloc] initWithFileURL:url];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
doc.persistentStoreOptions = options;
self.database=doc;
[doc release];
}
我遇到的问题是,即使每次更改 .xcdatamodel 的一点点,我都无法获取之前存储在文档中的所有内容,也无法创建任何新实例。事实上,这样做会产生以下异常:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.'
我认为设置托管文档的“选项”属性可以解决问题,但显然这还不够。 任何人都可以帮忙吗?找不到其他真正符合我确切需求的问题。
【问题讨论】:
-
我也关注了斯坦福 CS193P,我遇到了同样的错误。
标签: core-data core-data-migration uimanageddocument