Objective c CoreData持久存储出错
我正在使用一个基于CoreData的应用程序,并且有一个AppDelegate类,它是在应用程序启动时固有地编写的 单击按钮后,我将ArrayController(Section1)传递给一个子类并对其进行解析,以便存储TableView单元格值Objective c CoreData持久存储出错,objective-c,core-data,nsmanagedobjectcontext,nspersistentstore,Objective C,Core Data,Nsmanagedobjectcontext,Nspersistentstore,我正在使用一个基于CoreData的应用程序,并且有一个AppDelegate类,它是在应用程序启动时固有地编写的 单击按钮后,我将ArrayController(Section1)传递给一个子类并对其进行解析,以便存储TableView单元格值 - (IBAction)saveSect1:(NSButton *)sender { DataMiner *data = [[DataMiner alloc] init]; [data parseArrayController:Section1 ta
- (IBAction)saveSect1:(NSButton *)sender {
DataMiner *data = [[DataMiner alloc] init];
[data parseArrayController:Section1 tag:0];
}
-(void)parseArrayController:(NSArrayController *)myController tag:(NSInteger)arrayTag {
switch (arrayTag) {
case 0:
context = appDelegate().self.managedObjectContext;
for (NSMutableDictionary *mydict in myController.arrangedObjects) {
NSNumberFormatter *format = [[NSNumberFormatter alloc] init];
NSNumber *code = [format numberFromString:[mydict objectForKey:@"diagCode"]];
[format release];
Section_1 *section = nil;
section = [NSEntityDescription insertNewObjectForEntityForName:@"Section_1" inManagedObjectContext:context];
section.diagCode = code;
section.diagDescr = [mydict objectForKey:@"diagDescr"];
section.sectId = [NSNumber numberWithDouble:1];
section.subSectId = [NSNumber numberWithDouble:1.1];
}
NSLog(@"%@", context.registeredObjects);
[Section_1 release];
break;
default:
break;
}
}
最初运行良好,但现在我收到以下错误:
用于打开持久存储的托管对象模型版本与用于创建持久存储的版本不兼容。
以前有人遇到过这个错误吗?有什么建议吗?谢谢
- (NSManagedObjectModel *)managedObjectModel
{
if (__managedObjectModel) {
return __managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"CoreData_test" withExtension:@"momd"];
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return __managedObjectModel;
}
您的桌子型号已更改。您可以删除旧数据库(从设备/模拟器中删除已安装的应用程序)。更改代码中的路径或执行数据库迁移 通常在开发中,我只是删除旧的安装。(在模拟器中,转到重置内容和设置)如果需要保留填充的数据,则需要执行迁移
无论何时更改表格,您都需要执行此操作。这是谷歌上首次出现的错误,我认为这很好地解释了这一点。我很感激你的建议,这是用于基于iOS的应用程序还是MacOx?请您解释一下TableModel,因为我正在处理几个ViewController类,每个类都使用一个单独的NSTableView。我正在处理一个MacOSX应用程序,它使用了我在AppDelegate中添加的方法。Table Model可能是一个错误的术语。。。项目中的某个地方有一个xcdatamodel文件。在编译并运行项目之后,您是否更改了其中的任何内容?如果是,则此项目的现有数据库副本不再与您的文件兼容。您需要执行迁移或删除现有安装。非常感谢,已经成功!很高兴我能帮上忙:)请尽可能投票支持我!