Note that there are some explanatory texts on larger screens.

plurals
  1. POmost effective way of searching using NSPredicate OR statement
    text
    copied!<p>I tried to build a predicate in a previous post, but ended up doing it this way because after 3 hours, I couldn't get it to work.</p> <p>I feel like there has to be a more effective way, also I need the predicates to be case insensitive.</p> <p>10,000 cars I have a tire, wheel, seat as three car parts I want to find all cars that have a tire. THEN I want to find all cars that have a wheel. THEN I want to find all cars that have a seat. (I know many will be duplicates, but that's what I need)</p> <p>Please let me know if there is a more effective way. Also please let me know how to make the predicates case insensitive.</p> <p>Thank you in advance!</p> <pre><code>-(NSArray*) loadCarsFromCoreData:(NSMutableArray*)inputCarParts{ NSMutableArray *totalResults=[[NSMutableArray alloc]init]; NSFetchRequest *fetchRequest =[[NSFetchRequest alloc]init]; //To find the cars we are using the car parts NSEntityDescription *entity = [NSEntityDescription entityForName:@"CarParts" inManagedObjectContext:[self managedObjectContext]]; [fetchRequest setEntity:entity]; NSError *error; NSMutableArray *predicates =[self parseCarPartsIntoAPredicateArray:inputCarParts]; for (int i=0; i&lt;[predicates count]; i++) { [fetchRequest setPredicate:[predicates objectAtIndex:i]]; NSArray *records = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&amp;error]; NSLog(@"results = %i",[records count]); [totalResults addObjectsFromArray:records]; } NSLog(@"results = %i",[totalResults count]); return [NSArray arrayWithArray:totalResults]; } -(NSMutableArray*)parseCarPartsIntoAPredicateArray:(NSMutableArray*)inputCarParts{ NSMutableArray *returnArray=[[NSMutableArray alloc]init]; for (int i=0; i&lt;[inputCarParts count]; i++) { NSPredicate *predicate=[NSPredicate predicateWithFormat:@"partName == %@",[inputCarParts objectAtIndex:i]]; [returnArray addObject:predicate]; } return returnArray; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload