【发布时间】:2013-03-02 19:46:25
【问题描述】:
我有一个完全重写了之前版本的 iPhone 应用程序。但是当用户获得新版本时,会出现 Core Data 问题,因为某些实体具有相似的名称。我根本不想使用旧的数据模型。
我查看了关于不合并数据模型的 SO 帖子,而是使用 initWithContentsOfUrl。但是,所有示例都说首先获取 [NSBundle allBundles] 并遍历它以找到我想要的 DataModel。 https://groups.google.com/d/msg/restkit/6_iu2mLOgTo/mjwz2fSmHG4J
Core Data: Error, "Can't Merge Models With Two Different Entities Named 'foo' "
// Look for our managed object model in all of the bundles. (From the app
// it is in the main bundle but not for unit tests.)
NSString *modelPath = nil;
for (NSBundle* bundle in [NSBundle allBundles])
{
modelPath = [bundle pathForResource:@"MyDataModelFilename" ofType:@"momd"];
if (modelPath)
break;
}
NSAssert(modelPath != nil, @"Could not find managed object model.");
NSManagedObjectModel* mom = [[NSManagedObjectModel alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];
objectManager.objectStore =
[RKManagedObjectStore objectStoreWithStoreFilename:_databaseFilename
usingSeedDatabaseName:nil
managedObjectModel:mom
delegate:nil];
但是,当我这样做时,allBundles 中只有一个对象,并且该 URL 是整个 .app 文件本身的 URL,而不是特定的 '.xcdatamodeld' 文件。
那么我如何指向特定的“.xcdatamodeld”文件?我尝试对自己的 URLPath 进行硬编码,但分配的 MOM 始终为零 - 表明它在该 URL 处找不到模型。
【问题讨论】:
标签: ios objective-c core-data restkit