NSArray with NSPredicate using NOT IN

I have an NSArray that I want to filter out specific objects with NSPredicate, I was hoping I could use NOT IN since I saw that I can easily do IN.

So I have an array:

self.categoriesList 

Then I get the values ​​I want to delete:

 NSArray *parentIDs = [self.cateoriesList valueForKeyPath:@"@distinctUnionOfObjects.ParentCategoryID"]; 

This gives me a list of ParentCategoryID for categories that I DO NOT want to display, so I suppose I can use NSPredicate to remove them:

 self.cateoriesList = [self.cateoriesList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"CategoryID NOT IN %@",parentIDs]]; 

This fails:

 reason: 'Unable to parse the format string "CategoryID NOT IN %@"' 

If I wanted to use only IN, which works fine, of course.

+73
ios objective-c nsarray
Dec 20 '11 at 19:14
source share
2 answers

What about NOT (CategoryID IN %@) ?

+180
Dec 20 '11 at 19:18
source share

How about using NONE ?

 [NSPredicate predicateWithFormat:@"NONE CategoryID IN %@", parentIDs]; 
+1
Dec 20 '11 at 19:21
source share



All Articles