我在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;
}
有趣的是:我真的在这里、谷歌、AppleDevelopper上搜索过。。。我很确定我错过了什么。
- xcode-4-3-不可用加载-持久性-存储-字典-sqlite
- 用于打开存储的模型与用于创建
- 找不到源存储的模型
- cocoa-error-134100-增益-使用的模式-打开-与使用的模式不兼容-
- 不兼容的对象模型版本
- 如何创建神奇的xcdatamodeld文件夹包/4518137#4518137
所以我已经尝试了:
- 卸载模拟器上的应用程序+重置模拟器+项目清理和构建
- 手动删除模拟器设备文档文件夹中的.sqlite.mom.mod
- 创建另一个模型(空)进行测试,它也失败了,所以我已经删除了它的所有内容
- 在真正的iPhone上尝试过,同样的问题
然后我来了,如果我错过了已经在某个地方说过的话,我很抱歉,但我已经尝试了每个直接相关的问题和很多间接相关的问题。。。
如果你帮我的话,侮辱是可以的。
我通过试验找到了它,但我无法解释为什么。。。添加存储时,只需将配置设置为nil,而不是@"Default"。