将 BWOrderedManagedObject 与 NSFetchedResultsController 结合使用
我想使用 BWOrderedManagedObject< /code>
在 Core Data 中存储有序对象数组,使用
NSFetchedResultsController
显示数据。
但是,所有 BWOrderedManagedObject
的方法似乎只是返回一个有序对象数组;
NSFetchedResultsController
需要一个 NSFetchRequest
,对 NSFetchRequest
进行排序的唯一方法是提供一个 NSSortDescriptors
数组。
所以,我对如何使用 BWOrderedManagedObject
和 NSFetchedResultsController
- 有人知道我如何能够成功地做到这一点吗?
(我可能创建我自己的订购密钥并使用它 使用排序描述符,但我假设 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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
.