在运行时过滤 NSFetchedResultsController 结果
使用 NSFetchedResultsController 实现 Core Data 对象的运行时过滤的最佳方法是什么?
例如,我希望能够显示 RecordStore 实体中的所有记录实体,而且还可以针对某些预定义的条件过滤 RecordStore 中的所有记录,例如(ANY recordStore.records.count > 0)。
我读到,在创建 NSFetchedResultsController 的谓词后更改它是不好的。那么我应该将获取的结果存储在 NSArray 中,我可以过滤并将其用作 UITableView 的数据源,还是应该创建多个 NSFetchedResultsController?
What's the best way to implement runtime filtering of Core Data objects using NSFetchedResultsController?
For example, I want to be able to display all Record-entities in a RecordStore-entity, but also filter all Records in a RecordStore for some predefined critera, eg (ANY recordStore.records.count > 0).
I read that changing an NSFetchedResultsController's predicate after it has been created is bad. So should I store the fetched results in an NSArray that I can filter and use that as the UITableView's datasource, or should I create multiple NSFetchedResultsControllers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当需要更新时,可以重新获取数据。如果数据本身发生了变化,那么您只需再次调用 fetch 即可。如果您的标准发生变化,则在 NSFetchedResultsController 上设置谓词,然后调用 fetch。
You can re-fetch the data when you need to update. If the data itself changed, then you can just call fetch again. If your criteria changed, then set the predicate on your NSFetchedResultsController, and call fetch.
创建 NSFetchRequest 实例,每次更新请求并执行 fetch。如果您使用的是删除缓存:
请阅读苹果文档: https://developer.apple.com/参考/coredata/nsfetchedresultscontroller
Create the NSFetchRequest instance, update request each time and perform fetch. Delete cache if you are using:
Read the apple document: https://developer.apple.com/reference/coredata/nsfetchedresultscontroller