我正在尝试使用CoreData配置RestKit。我得到了“无法找到源存储模型”的错误。我使用的是Restkit RKTwitterCoreData示例中的配置。我在堆栈溢出时发现了一些类似的帖子,人们说要删除数据库,但我不知道怎么做,我在手机上运行,而不是模拟器。我还试图做一个产品:干净但同样的错误。
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模板的默认代码,两种方式都出错了。注意:我不确定“importer 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
答案 0 :(得分:1)
您似乎更改了核心数据模型的版本,并且没有要求核心数据尝试自动迁移或明确提供迁移。因此,当核心数据加载时,它会检测版本不匹配并中止。
最初,从您的设备中删除该应用并重新安装,一切都应该再次运行。每次更改数据模型时都需要这样做。
显然,这样去App Store并不是一个好主意,所以你应该研究自动迁移及其约束和(如果需要)显式迁移。
答案 1 :(得分:0)
要删除数据库,只需删除sqlite文件,该文件应位于地址/var/mobile/Applications/2E1DA997-E54E-4CE3-AC62-6552445D77CF/Documents/JustD.sqlite 考虑你记录
在控制台中: rm /var/mobile/Applications/2E1DA997-E54E-4CE3-AC62-6552445D77CF/Documents/JustD.sqlite
答案 2 :(得分:0)
您是否确保将种子数据库添加到构建阶段:复制捆绑资源?
我几个小时都遇到了同样的问题,最后它就像那样简单。即使查看模拟器部署的应用程序包,种子sqlit文件仍然是,但由于某种原因,managedObjectStore无法找到它,但返回了“无法找到模型”对于源存储“错误而不是,&#34;无法找到种子数据文件&#34;哪个会更有帮助!