NSManagedObject using on specified queue

163 Views Asked by At

I have a background task that is running on background queue. I need to load some NSManagedObjects in this task. I know I need to use private context but how to bound this context to my existing background queue so I can use this NSManagedObjects in my background task? Should I perform in this background task performBlock or performBlockAndWait or maybe I should just call from UI Thread performBlock on private NSManagedObjectContext and use queue from this context to perform any background task including loading saving NSManagedObjects and other background tasks like communicating with rest-api, etc...

I'm just not sure that I can use this queue from context to do any additional tasks not related to CoreData NSManagedObjects? If not how to use those NSManagedObjects in queue that I created for my task?

1

There are 1 best solutions below

0
On

Although queue management can always be tricky, queues spun by Core Data can run code like any other queues.

In particular, you can use a queue from the managed object context to do additional tasks not related to Core Data or its managed objects. When Core Data was first released on macOS in 2005, managed objects had to be accessed on the main thread, which of course could be quite busy with other tasks.