我在 xcode 6.0.1 中创建了一个核心数据模型,然后我开始通过创建一个具有三个获取请求的简单实体来测试框架的可能性。 我使用了xcode工具。
(抱歉无法发布图片)
RequestTask{
String argnames
String argvalues
Integer16 type
String method
}
我做了一些基本测试:创建、获取、更新和删除。一切都工作正常,直到我收到那个著名的错误消息:
编辑:即使第一次创建商店时也会发生此错误,那么用于创建商店的模型如何与几行后用于打开商店的模型不同?
Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x7a6e0a80 {metadata={
NSPersistenceFrameworkVersion = 519;
NSStoreModelVersionHashes = {
RequestTask = <835609ac 6e164427 c573e9d7 c56ba74e b1cc0283 75a99bb9 0e74286d c95ce429>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "7D5176D6-DBFE-41B3-825C-BEE1F8E74B3E";
"_NSAutoVacuumLevel" = 2;
}, reason=The model used to open the store is incompatible with the one used to create the store}, {
metadata = {
NSPersistenceFrameworkVersion = 519;
NSStoreModelVersionHashes = {
RequestTask = <835609ac 6e164427 c573e9d7 c56ba74e b1cc0283 75a99bb9 0e74286d c95ce429>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = SQLite;
NSStoreUUID = "7D5176D6-DBFE-41B3-825C-BEE1F8E74B3E";
"_NSAutoVacuumLevel" = 2;
};
reason = "The model used to open the store is incompatible with the one used to create the store";
}
我刚刚使用模板代码将核心数据应用程序与 AppleDev 上的一些示例一起使用。
#pragma mark - Core Data stack
// Returns the managed object context for the application.
// If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
- (NSManagedObjectContext *)managedObjectContext
{
if (_managedObjectContext != nil) {
return _managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
}
return _managedObjectContext;
}
// Returns the managed object model for the application.
// If the model doesn't already exist, it is created from the application's model.
- (NSManagedObjectModel *)managedObjectModel
{
if (_managedObjectModel != nil) {
return _managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"AppBesson" withExtension:@"momd"];
//NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"TestModel" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return _managedObjectModel;
}
// Returns the persistent store coordinator for the application.
// If the coordinator doesn't already exist, it is created and the application's store added to it.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"appbesson.sql"];
//NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"testmodel.sql"];
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES};
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:@"Default" URL:storeURL options:nil error:&error]) {
/*
...
*/
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}
这是有趣的部分:我确实在这里、Google、AppleDevelopper 上进行了搜索...我很确定我错过了一些东西。
- xcode-4-3-unable-to-load-persistent-store-userdictionary-sqlite
- the-model-used-to-open-the-store-is-incompatible-with-the-one-used-to-create-the
- cant-find-model-for-source-store
- cocoa-error-134100-again-model-used-to-open-is-incompatible-from-model-used-t
- incompatible-object-model-version
- how-to-create-the-magic-xcdatamodeld-folder-package/4518137#4518137
所以我已经尝试:
- 卸载模拟器上的应用 + 重置模拟器 + 项目清理和构建
- 手动删除模拟器设备文档文件夹中的.sqlite .mom .momd
- 创建另一个模型(空)进行测试,它也失败了,所以我删除了有关它的所有内容
- 在真正的 iPhone 上尝试过,同样的问题...
然后我来了,如果我错过了某处已经说过的内容,我很抱歉,但我已经尝试了所有直接相关的问题和很多间接相关的问题......
如果你帮助我,侮辱也没关系。
最佳答案
我通过试验找到了它,但我无法解释为什么...... 添加商店时只需将配置设置为nil,而不是@"Default"。
关于ios - cocoa又报错134100(开店的模型与创建商店的模型不兼容),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26185354/