Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an NSFetchRequest which asks for objects that have a specific firstname?

For example, I have a Managed Object Model with an Entity called "Friends", and a friend has a firstName. I want to get all friends where the firstName is equal to "George". How can I do that?

like image 362
dontWatchMyProfile Avatar asked Feb 11 '10 15:02

dontWatchMyProfile


1 Answers

Use this:

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];
like image 200
diederikh Avatar answered Nov 10 '22 00:11

diederikh