NSArray 与 NSPredicate 使用 NOT IN
我有一个 NSArray,我想使用 NSPredicate 过滤掉某些对象,我希望我可以使用 NOT IN,因为我看到我可以轻松地执行 IN。
所以我有我的数组:
self.categoriesList
然后我得到了我想要删除的值:
NSArray *parentIDs = [self.cateoriesList valueForKeyPath:@"@distinctUnionOfObjects.ParentCategoryID"];
这给了我一个我不想显示的类别的 ParentCategoryID 列表,所以我想我可以使用 NSPredicate 来删除它们:
self.cateoriesList = [self.cateoriesList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"CategoryID NOT IN %@",parentIDs]];
这失败了:
reason: 'Unable to parse the format string "CategoryID 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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NOT (CategoryID IN %@)
怎么样?What about
NOT (CategoryID IN %@)
?使用
NONE
怎么样?How about using
NONE
?