10

例如,我有一个托管对象模型,其中包含一个名为“Friends”的实体,而一个朋友有一个名字。我想得到所有名字等于“乔治”的朋友。我怎样才能做到这一点?

4

1 回答 1

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];
于 2010-02-11T15:58:41.710 回答