How to properly trim object graph brought in by NSFetchedResultsController?

孤人 提交于 2019-12-20 05:29:07

问题


Without reference cycles NSFetchedResultsController can turn its managed objects into fault properly when they are not needed. But with reference cycles, it not, so I have to re-fault those objects myself. However, manually re-faulting objects managed by NSFetchedResultsController is dangerous. So I want know what you Core Data experts think is the best way to trim object graph brought in by NSFetchedResultsController. Thanks.

Update:

I believe normally FRC should be able to re-fault objects, even with reference cycles. I have the impression that it is not because of an old bug that I reported to Apple in 2012 whose state is still Open: FRC never re-faults newly inserted objects (after saving), so I have to manually re-fault them. Here is my test project: http://d.pr/f/Ohe3.


回答1:


As I mentioned in my comments HERE, the FRC is responsible to fault-in or fault-out the objects it fetched.
Which in turn break any strong reference cycles between your managed objects.

You can test this by setting a breakpoint in your objects willTurnIntoFault method when scrolling a large enough table.

This is done with no regards as to what other objects reference these fetched objects (as far as I can tell).




回答2:


I think you should simply avoid strong reference cycles. Usually, there is no compelling reason to have to deal with the problem you describe.

For a detailed discussion, see Apple's Encapsulating Data chapter of the Programming with Objective-C guide where you will find a section titled Avoid Strong Reference Cycles.



来源:https://stackoverflow.com/questions/20954690/how-to-properly-trim-object-graph-brought-in-by-nsfetchedresultscontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!