KVC 按标准选择

发布于 2024-08-13 09:20:49 字数 53 浏览 2 评论 0原文

我有一系列从核心数据中选择的对象。我需要从这组对象子集中选择与条件相对应的对象。 怎么做呢?

I have a array of objects that selected from core data. I need select from this set subset of object that correspond to condition.
How to do it?

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

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

发布评论

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

评论(1

我很OK 2024-08-20 09:20:49

如果我没看错的话,您想根据数组中某些对象满足的条件来过滤数组吗?

您可以通过使用 NSPredicate 并在数组上调用 filteredArrayWithPredicate: 来完成此操作。

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"attribute == YES"];
NSArray *filteredArray = [originalArray filteredArrayWithPredicate:predicate];

您可以在谓词编程指南中阅读有关使用谓词的更多信息

当从 Core Data 检索数据时,您还可以使用谓词直接过滤您的 NSFetchRequest

If I read you correctly you want to filter your array based on a condition met by some of the objects in it?

You can do this by using NSPredicate and call filteredArrayWithPredicate: on your array.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"attribute == YES"];
NSArray *filteredArray = [originalArray filteredArrayWithPredicate:predicate];

You can read more about using predicates in the Predicates Programming Guide

You can also use predicates to filter your NSFetchRequest directly when retrieving the data from Core Data.

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