将 BWOrderedManagedObject 与 NSFetchedResultsController 结合使用

发布于 2024-09-09 09:17:16 字数 1235 浏览 2 评论 0原文

我想使用 BWOrderedManagedObject< /code>在 Core Data 中存储有序对象数组,使用 NSFetchedResultsController 显示数据。

但是,所有 BWOrderedManagedObject的方法似乎只是返回一个有序对象数组; NSFetchedResultsController 需要一个 NSFetchRequest,对 NSFetchRequest 进行排序的唯一方法是提供一个 NSSortDescriptors 数组。

所以,我对如何使用 BWOrderedManagedObjectNSFetchedResultsController - 有人知道我如何能够成功地做到这一点吗?

(我可能创建我自己的订购密钥并使用它 使用排序描述符,但我假设 BWOrderedManagedObject 会更健壮......?)

I would like to use BWOrderedManagedObject to store an array of ordered objects in Core Data, using NSFetchedResultsController for displaying the data.

However, all of BWOrderedManagedObject's methods seem to simply return an array of ordered objects; NSFetchedResultsController requires an NSFetchRequest, and the only way to sort an NSFetchRequest is to provide an array of NSSortDescriptors.

So, I'm a bit stuck here as to how to use BWOrderedManagedObject with NSFetchedResultsController—does anyone know how I might be able to successfully do this?

(I could probably create my own ordering key and use this with the sort descriptors, but I'm assuming that BWOrderedManagedObject would be more robust...?)

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

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

发布评论

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

评论(1

银河中√捞星星 2024-09-16 09:17:16

NSFetchedResultsController 期望从无序集合中获取信息并返回数组。这就是为什么它需要一个排序描述符。它必须将无序集转换为数组,并且需要排序来做到这一点。

我认为实现您自己的排序是最简单的。我使用与“排序”实体的关系,该实体只不过是索引属性和与排序实体的关系。然后您所要做的就是排序并获取 Ordering 对象,然后遍历它们各自的关系以按顺序查找目标对象。它快速、干净、灵活,并且可与 NSFetchedResultsController 配合使用。

NSFetchedResultsController expects to be fetching information from unordered sets and returning arrays. That is why it wants a sort descriptor. It has to convert the unordered set into an array and it needs the sort to do that.

I think it would easiest to implement your own ordering. I use a relationship to an "Ordering" entity that is nothing but an index attribute and a relationship to the ordered entity. Then all you have to do is sort and fetch the Ordering objects and then walk their individual relationships to find the target objects in order. It's fast, clean, flexible and works with NSFetchedResultsController.

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