Iphone 核心数据无法识别的选择器发送到实例错误:并且无法调用NSManagedObject类上指定的初始值设定项
我尝试了下面的代码来更新核心数据中的对象,但出现了错误Iphone 核心数据无法识别的选择器发送到实例错误:并且无法调用NSManagedObject类上指定的初始值设定项,iphone,core-data,Iphone,Core Data,我尝试了下面的代码来更新核心数据中的对象,但出现了错误 NSError *error; NSArray *objects = [managedObjectContext executeFetchRequest:fetchRequest error:&error]; NSLog(@"objects %@",objects); // yourIdentifyingQualifier is unique. It just grabs the first ob
NSError *error;
NSArray *objects = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSLog(@"objects %@",objects);
// yourIdentifyingQualifier is unique. It just grabs the first object in the array.
AllChallenge *tempChallenge = [[managedObjectContext executeFetchRequest:fetchRequest error:&error] objectAtIndex:0];
tempChallenge =[[AllChallenge alloc] init];
NSLog(@"tempchallenge >>>>> %@",tempChallenge);
// update the object
tempChallenge.status = 1;
[self.managedObjectContext save:&error];
编译后,我得到CoreData:错误:未能调用NSManagedObject类“AllChallenge”上的指定初始值设定项。谢谢你的帮助 如果要更新现有对象,则不应将其替换为新对象
分配一个:
AllChallenge *tempChallenge = [[managedObjectContext executeFetchRequest:fetchRequest error:&error] objectAtIndex:0];
// tempChallenge =[[AllChallenge alloc] init]; // <-- REMOVE THIS LINE
tempChallenge.status = 1;
[self.managedObjectContext save:&error];
objAllChallenge
来自哪里?你想写tempChallenge
?是的,我是说tempChallenge。问题是你在代码中使用tempChallenge还是objAllChallenge。这不是问题。
AllChallenge *tempChallenge = [NSEntityDescription insertNewObjectForEntityForName:@"AllChallenge" inManagedObjectContext: managedObjectContext];