Iphone 如何发出NSFetchRequest请求具有特定名字的对象?

Iphone 如何发出NSFetchRequest请求具有特定名字的对象?,iphone,core-data,nspredicate,nsfetchrequest,Iphone,Core Data,Nspredicate,Nsfetchrequest,例如,我有一个托管对象模型,其中有一个名为“Friends”的实体,Friends有一个名字。我想结交所有名字等于“乔治”的朋友。我如何才能做到这一点?使用以下方法: NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Friends" inManagedObjectContext:context]; NSFetchRequest *request = [[[NSFetchRequest

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

使用以下方法:

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];