The Nomad
The Nomad

Reputation: 7425

Core Data: managedObjectContext where to use performBlock or performBlockAndWait

Using the Parent/Child context model for using Core Data with multithreading, when should you be calling the performBlock or performBlockAndWait functions?

Should they be called only when saving the changes from the Child context to the Parent context? Thus, after you have already made the changes to the Core Data records (in the child context)?

Or would you call performBlock while you are doing the actual changes to the Core Data records? As well as when saving the changes to the child then parent contexts?

Upvotes: 0

Views: 453

Answers (1)

Andy Riordan
Andy Riordan

Reputation: 1154

The general rule is that you should always use performBlock: or performBlockAndWait: when doing any operation involving that context, including just reading objects. The only exceptions are main queue contexts (where you can use performBlock: if you wish, but there's no requirement to if you're on the main thread), and thread confinement contexts (which are deprecated anyway, and you likely have no reason to use anymore.)

Upvotes: 2

Related Questions