例如,我有一个名为“Friends”的实体的托管对象模型,而朋友有firstName。我想得到firstName等于“George”的所有朋友。我怎么能这样做?
答案 0 :(得分:21)
使用此:
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Friends" inManagedObjectContext:context];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:entityDescription];
[request setPredicate:[NSPredicate predicateWithFormat:@"firstName == 'George'"]];
NSError *error = nil;
NSArray *array = [context executeFetchRequest:request error:&error];