Mac Version:10.6.7
XCode Version:4.2
参考书籍:Iphone3开发基础教程中文版第十一章关于数据保存技术------Core Data
在- (void)viewDidLoad 函数中
有如下的代码:
NSManagedObjectContext *context = [appDelegate managedObjectContext];
运行到这里就出错,错误提示信息:
2011-12-23 11:35:25.865 Core Data Persistence[1115:207] Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x6a3e420 {metadata=<CFBasicHash 0x6a275b0 [0x171bb38]>{type = immutable dict, count = 7, entries => ...............
http://stackoverflow.com/questions/5517129/core-data-cocoa-error-134100
进行如下的操作就能解决问题:
找到该应用程序沙箱的Documents文件夹,删除CoreData需要的那个文件。
用以下的方法可以找到沙箱的Documents文件夹:
- (NSString *) dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@"test.txt"];
}
产生这种错误的步骤:
1.编写xcdatamodeld文件的时候,添加一个ENTITIES(命名为entitie)
2.给entitie添加了2个属性a和b
3.运行程序,不会在NSManagedObjectContext *context = [appDelegate managedObjectContext];这里出现错误,但是有很大的可能在其他地方出错
4.重命名entitie为Line
5.运行程序,这个时候就出现错误
最后总结该错误的原因:
The reason for this is because your new managed object model is trying to use older version of storage (the one first time created when you launched the app).
摘自:http://stackoverflow.com/questions/5517129/core-data-cocoa-error-134100