0
我对Core Data很新,实际上Objective-C是一个整体,所以我希望我正确地表述了这一点,我已经能够使用Core Data存储和检索数据,但我挣扎着通过结果集循环,通过NSFetchRequest循环结果
// read the data
NSFetchRequest *req = [[NSFetchRequest alloc]init];
[req setEntity:[NSEntityDescription entityForName:@"Card" inManagedObjectContext:app.managedObjectContext]];
//[req setPredicate:[NSPredicate predicateWithFormat:@"cardID == %@", @"1"]];
NSArray *crd = [[app.managedObjectContext executeFetchRequest:req error:nil] lastObject];
for(Card *card in crd){
NSLog(@"%@",card.backImageURL);
}
我不断收到这个错误,虽然当我尝试运行应用程序,
2012-10-16 11:37:29.407 Core test[925:17903] -[Card countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x962f5c0
2012-10-16 11:37:29.408 Core test[925:17903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Card countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x962f5c0'
我相信这是一些非常简单的,但由于某种原因,我可以”似乎查明问题。
哇哦......我没甚至不会注意到'lastObject'! -_-谢谢你,那就是诀窍! – Odyss3us