Can NSPredicate Compare a Property to an Array of Wildcards?

50 Views Asked by At

I need an NSPredicate that compares a property to an array of wildcards. Something like...

NSArray *collection = @[@"Jerry*",@"George*",@"Elaine*"];
[NSPredicate predicateWithFormat:@"property LIKE IN %@", collection];

Is this possible?

1

There are 1 best solutions below

0
ThinkCL On BEST ANSWER

I ended up using NSCompoundPredicate to get this done. I was hoping there was a shorter route but it's fairly painless.

NSArray *collection = @[@"Jerry*",@"George*",@"Elaine*"];
NSMutableArray *thePredicateArray = [NSMutableArray arrayWithCapacity:3];
        
for (id *theItem in collection)
   {
   [thePredicateArray addObject:[NSPredicate predicateWithFormat:@"property LIKE %@",theItem]];
   }    
    
NSCompoundPredicate *theCompoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:thePredicateArray];