如何编写 NSPredicate 来获取 id 位于数组中的所有项目?

发布于 2024-12-04 08:16:47 字数 378 浏览 3 评论 0原文

在我的核心数据数据库中,每个项目都有一个字符串 id,它是一个 url,指示该项目属于谁。

现在我有一个数组,其中包含 200 个所有者 url(200 只是一个示例,它在应用程序中是动态的)。我希望获取属于 200 个自己的 url 的所有项目。

如果只有 1 个所有者 url,我知道如何编写:

[NSPredicate predicateWithFormat:@"(ownerUrl == %@)", url]

所有者 url 数组怎么样,比如 200 个?

顺便说一句,我使用的核心数据是sql。我认为 sql 会忽略 NSPredicate 中的 "IN"

谢谢

In my core data db, every item has a string id which is an url to indicate whom this item belongs to.

Now I have an array which contains, say, 200 owner urls (200 is just an example, it is dynamic in the app). I wish to fetch all items that belong to the 200 own urls.

If only 1 owner url, I know how to write:

[NSPredicate predicateWithFormat:@"(ownerUrl == %@)", url]

What about an array of owner urls, say 200?

by the way, the core data I am using is sql. I think sql will ignore "IN" in NSPredicate?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

莫言歌 2024-12-11 08:16:47

试试这个:

NSSet *urls = [NSSet setWithObjects:@"url1", @"url2", @"url3", nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K IN %@", @"ownerUrl", urls];

Try this :

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