使用 NSPredicate 获取结果控制器与核心数据 NSSet

发布于 2024-09-13 12:34:45 字数 283 浏览 9 评论 0原文

好的,我有一个 UITableView 层次结构。顶级控制器用于类别,通过获取结果控制器选择类别,没有类别实体的谓词。

当用户点击单元格时,他们将前进到项目表视图控制器。

此时,我假设我应该使用另一个带有 NSPredicate 的获取结果控制器来过滤掉与选择类别不匹配的结果。

然而,我在构建执行此操作的谓词时遇到了很多困难。所有示例似乎都是搜索字符串与属性比较。不比较 CoreData 关系。

那么使用这种方法是更好的做法,还是简单地从传入的类别托管对象中获取项目的 NSSet ?

Okay, so I have a UITableView hierarchy. The top level controller is for Categories, which are selected via Fetched Results Controller with no predicate for the Category Entity.

When a user taps a cell, they are advanced to the Items Table View Controller.

At this point, I assumed I should use another fetched results controller with an NSPredicate to filter out the results not matching the selecting category.

However, I've had a lot of difficulty building a predicate that does this. All the examples seem to be for search strings to attribute comparisons. Not comparing a CoreData Relationship.

So is it a better practice to use this method, or simply get the NSSet of items from the passed in Category Managed Object?

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

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

发布评论

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

评论(1

沉溺在你眼里的海 2024-09-20 12:34:45

您的第二级视图控制器应该通过依赖项注入将选定的类别设置为属性。您的第二级视图控制器应该只知道“它的”类别是 X。它根本不需要 NSFetchedResultsController,因为您已经通过“它的”类别实体上的关系获得了所需的所有信息。

为此,在顶级视图控制器中,当选择类别时,您可以通过 NSFetchedResultsController 获得指向该类别的指针,实例化新的视图控制器,设置类别属性,然后推送新的视图控制器。

这将为您提供视图控制器之间的牢固封装和分离。

Your second level view controller should have the selected Category set into it via dependency injection as a property. Your second level view controller should only know that "it's" Category is X. It does not need a NSFetchedResultsController at all because you already have all of the information you require via relationships on "it's" Category entity.

To do this, in your top level view controller when a Category is selected you get a pointer to it via the NSFetchedResultsController, instantiate the new view controller, set the Category property and then push the new view controller.

This will give you solid incapsulation and separation between your view controllers.

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