ios - Restkit 0.20 CoreData error "Can' t find model for source store”

标签 ios objective-c core-data restkit

我正在尝试使用 CoreData 配置 RestKit。我收到错误“找不到源商店的模型”。我使用的是 Restkit RKTwitterCoreData 示例中的配置。我在堆栈溢出上发现了一些类似的帖子,人们说要删除数据库,但我不知道该怎么做,我在手机上运行,​​而不是模拟器。我也尝试做一个 Product:Clean 但同样的错误。

 2014-05-18 12:29:16.489 What my life could be[7006:60b] I restkit:RKLog.m:34 RestKit logging initialized...
2014-05-18 12:29:17.259 What my life could be[7006:60b] *** Assertion failure in -[AppDelegate application:didFinishLaunchingWithOptions:], /Users/Pro/Desktop/ios app/What my life could be/What my life could be/AppDelegate.m:161
2014-05-18 12:29:17.262 What my life could be[7006:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to add persistent store with error: Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x15d7fc40 {URL=file:///var/mobile/Applications/2E1DA997-E54E-4CE3-AC62-6552445D77CF/Documents/JustD.sqlite, metadata={
NSPersistenceFrameworkVersion = 479;
NSStoreModelVersionHashes =     {
    ActivityEntity = <fdd7d538 648131cf 2fe3b684 bd55169e 85a7cee4 cbec3080 94202e4c 26b97889>;
    PriorityEntity = <74cd93d0 00ade70c ef4d0ea3 f177762d 7d342720 7aba6945 d83ee02d 96a2135c>;
    UserDataEntity = <2ffd8aec e7c1dacc 23e14fdd 400b60c0 5a1cd9a8 07fe6138 4d0e5a30 8e0c6e28>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers =     (
    ""
);
NSStoreType = SQLite;
NSStoreUUID = "B1BC3FFF-F727-49E4-A44F-5C5216C58226";
"_NSAutoVacuumLevel" = 2;}, reason=Can't find model for source store}'
*** First throw call stack:(0x2ec07e83 0x38f646c7 0x2ec07d55 0x2f5b00af 0xf37bb 0x313fcaad 0x313fc4f3 0x313f6b41 0x31391a07 0x31390cfd 0x313f6321 0x3387676d 0x33876357 0x2ebd2777 0x2ebd2713 0x2ebd0edf 0x2eb3b471 0x2eb3b253 0x313f55c3 0x313f0845 0xf3bc5 0x3945dab7)
libc++abi.dylib: terminating with uncaught exception of type NSException(lldb) 

配置商店的代码部分。我删除了 CoreData 模板默认代码,两种方式都出现错误。注意:我不确定“导入器 importObjectsFromItemAtPath:....”如何工作。

#ifdef RESTKIT_GENERATE_SEED_DB
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelInfo);
RKLogConfigureByName("RestKit/CoreData", RKLogLevelTrace);

NSError *error = nil;
BOOL success = RKEnsureDirectoryExistsAtPath(RKApplicationDataDirectory(), &error);
if (! success) {
    RKLogError(@"Failed to create Application Data Directory at path '%@': %@", RKApplicationDataDirectory(), error);
}
NSString *seedStorePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"JustDid.sqlite"];
RKManagedObjectImporter *importer = [[RKManagedObjectImporter alloc] initWithManagedObjectModel:managedObjectModel storePath:seedStorePath];
[importer importObjectsFromItemAtPath:[[NSBundle mainBundle] pathForResource:@"activities" ofType:@"json"]
                          withMapping:activityMapping
                              keyPath:@"activity"
                                error:&error];
[importer importObjectsFromItemAtPath:[[NSBundle mainBundle] pathForResource:@"users" ofType:@"json"]
                          withMapping:userMapping
                              keyPath:@"user"
                                error:&error];
BOOL success = [importer finishImporting:&error];
if (success) {
    [importer logSeedingInfo];
} else {
    RKLogError(@"Failed to finish import and save seed database due to error: %@", error);
}

// Clear out the root view controller
[self.window setRootViewController:[UIViewController new]];
#else
/**
 Complete Core Data stack initialization
 */
[managedObjectStore createPersistentStoreCoordinator];
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"JustD.sqlite"];
NSString *seedPath = [[NSBundle mainBundle] pathForResource:@"RKSeedDatabase" ofType:@"sqlite"];
NSError *error;
NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:seedPath withConfiguration:nil options:nil error:&error];
NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);

// Create the managed object contexts
[managedObjectStore createManagedObjectContexts];

// Configure a managed object cache to ensure we do not create duplicate objects
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
#endif

最佳答案

您似乎更改了核心数据模型的版本,并且没有要求核心数据尝试自动迁移或显式提供迁移。因此,当核心数据加载时,它会检测到版本不匹配并中止。

首先,从您的设备中删除该应用并重新安装,一切都会恢复正常。每次更改数据模型时都需要执行此操作。

显然,像这样访问 App Store 并不是一个好主意,因此您应该研究自动迁移及其限制以及(如果需要)显式迁移。

关于ios - Restkit 0.20 CoreData error "Can' t find model for source store”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23726045/

相关文章:

ios - 在 webRTC iOS 中设置视频大小

ios - xcode 5 UITableView 总是填满屏幕的整个长度

ios - 面向初学者的变量赋值和字符串数组 Obj-c (iOS)

objective-c - NSPrintInfo 共享 PrintInfo 到底是如何共享的?

swift - Xcode Swift在项目中使用.db数据库

iOS 8+ 从后台恢复应用程序时核心数据故障

cocoa - 如何在 CoreData 中存储 typedef 枚举

iphone - 如何关闭相机并导航到 Root View Controller ?

iphone - 无法在包 : 'NSBundle when using storyboarding 中加载 NIB

ios - 获取 NSString 中所有大写字母的 NSRange 对象数组的最快方法?