I have an NSArray that I want to filter out certain objects using an NSPredicate, I was hoping I could use NOT IN since I saw that I can easily do an IN.
So I have my array:
self.categoriesList
Then I get the values I want to remove:
NSArray *parentIDs = [self.cateoriesList valueForKeyPath:@"@distinctUnionOfObjects.ParentCategoryID"];
This gives me a list of ParentCategoryID's for categories I DO NOT want to display, so I figure I can use an 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 just IN that works perfectly of course.
arrays can't contain nil.
In Objective-C, the compiler generates code that makes an underlying call to the init(objects:count:) method. id objects[] = { someObject, @"Hello, World!", @42 }; NSUInteger count = sizeof(objects) / sizeof(id); NSArray *array = [NSArray arrayWithObjects:objects count:count];
NSDictionary can use predicates by filtering its keys or values (both NSArray objects). NSOrdered Set can either create new ordered sets from a filtered NSArray or NSSet, or alternatively, NSMutable Set can simply remove Objects In Array:, passing objects filtered with the negated predicate.
NSDictionary can use predicates by filtering its keys or values (both NSArray objects). NSOrderedSet can either create new ordered sets from a filtered NSArray or NSSet, or alternatively, NSMutableSet can simply removeObjectsInArray:, passing objects filtered with the negated predicate.
Any subclass of NSArray must override the primitive instance methods count and object (at:). These methods must operate on the backing store that you provide for the elements of the collection. For this backing store you can use a static array, a standard NSArray object, or some other data type or mechanism.
In addition to the provided instance methods, such as object (at:), you can access NSArray values by their indexes using subscripting. There is typically little reason to subclass NSArray. The class does well what it is designed to do—maintain an ordered collection of objects.
What about NOT (CategoryID IN %@)
?
How about using NONE
?
[NSPredicate predicateWithFormat:@"NONE CategoryID IN %@", parentIDs];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With