Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

core data - fetch attribute that match one of the values in an array

My core data model:

Person 
======
personId  (NSNumber)

This is a basic core data question,
I have an array of personIds (not Person, just NSNumber of ids) and I want to fetch all the Persons with corresponding id in the array.

This is how I fetch a person that correspond to one id:

   NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Person"];
   request.predicate = [NSPredicate predicateWithFormat:@"personId = %@", onePersonId];

I'm looking for a way to fetch multiple persons that match to multiple ids

like image 590
Mario Avatar asked Mar 06 '14 15:03

Mario


1 Answers

Use 'IN' match for this:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"personId IN %@", idsArray];
like image 183
ksh Avatar answered Sep 28 '22 15:09

ksh