使用NOT IN的NSArray与NSPredicate [英] NSArray with NSPredicate using NOT IN
本文介绍了使用NOT IN的NSArray与NSPredicate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个NSArray,我想使用NSPredicate过滤掉某些对象,我希望可以使用NOT IN,因为我看到自己可以轻松地进行IN.
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.
所以我有我的数组:
self.categoriesList
然后我得到了要删除的值:
Then I get the values I want to remove:
NSArray *parentIDs = [self.cateoriesList valueForKeyPath:@"@distinctUnionOfObjects.ParentCategoryID"];
这为我提供了我不想显示的类别的ParentCategoryID列表,因此我认为可以使用NSPredicate删除它们:
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]];
此操作失败:
reason: 'Unable to parse the format string "CategoryID NOT IN %@"'
如果我只想使用IN,那当然很好.
If I wanted to use just IN that works perfectly of course.
推荐答案
NOT (CategoryID IN %@)
呢?
这篇关于使用NOT IN的NSArray与NSPredicate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文