NSFetchedResultsController: Fetch in a background thread

后端 未结 3 1834
无人共我
无人共我 2020-12-16 03:02

I have a more or less basic UITableViewController with a NSFetchedResultsController. The UITableViewController is pushed onto the

3条回答
  •  一生所求
    2020-12-16 03:30

    The general rule with Core Data is one Managed Object Context per thread, and one thread per MOC. With that in mind you need to perform the fetch for the Fetched Results Controller on the main thread, as this is the thread that will be interacting with the FRC's Managed Objects. (See Core Data Programming Guide - Concurrency with Core Data)

    If you are having performance issues with the animation you should probably look at ways to ensure that the fetch is performed before or after the view is pushed. Normally you would perform the fetch in the view controller's viewDidLoad:, and the navigation controller wouldn't push the view until the fetch was complete.

提交回复
热议问题