-2

How to use multithreading with blocks and NSOperation and NSOperationQueue so that there are no problems with concurrency?

1 Answers1

0

The correct way to use Core Data is either with a MainQueue context or a PrivateQueue context. If you are using Core Data in a NSOperation then you need to either access the MainQueue context via performBlock: or performBlockAndWait:. If you are going to use a PrivateQueue context then you still need to access it via performBlock: or performBlockAndWait: the primary difference between the two is that any work done against the MainQueue context will block the user interface.

Ideally if you are processing data in an NSOperation then you should construct a PrivateQueue context that is a child of the MainQueue context, access it via performBlock: or performBlockAndWait: and save it when you are done processing the data.

I strongly suggest reviewing the Core Data Programming Guide and the section on Concurrency.

Marcus S. Zarra
  • 46,571
  • 9
  • 101
  • 182