NSArray 与 NSPredicate 使用 NOT IN

发布于 2024-12-22 07:40:11 字数 672 浏览 8 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

给妤﹃绝世温柔 2024-12-29 07:40:11

NOT (CategoryID IN %@) 怎么样?

What about NOT (CategoryID IN %@)?

惟欲睡 2024-12-29 07:40:11

使用NONE怎么样?

[NSPredicate predicateWithFormat:@"NONE CategoryID IN %@", parentIDs];

How about using NONE?

[NSPredicate predicateWithFormat:@"NONE CategoryID IN %@", parentIDs];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文