简体   繁体   中英

How to use CoreData effectively in fetching many Managed Objects in the background and updating UI on the main thread?

I am trying to fetch thousands of NSManageObjects in the background and update UI using those objects on the main thread. In the Apple document, It is written that the developer should pass the objectId of NSManagedObject when use the same objects between the threads. But, I think it is inefficient to fetch again by objectId on the main thread.

One way to avoid it is to create the subclass of NSObject to hold the attributes of NSManagedObject which to be needed to update UI and set it to the array, and use that array on the main thread.

Is there any good idea?

You are asking a question that has been answered on this site so many times.

The easiest solution for you is to work with a background context to insert and update your new data and rely on the practical NSFetchedResultsController , using a main thread context, to update your UI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM