Daniel Galasko
Daniel Galasko

Reputation: 24247

Modern solution to accessing an NSManagedObjectContext across threads or queues

I came across this fascinating post and in particular, this paragraph by an Apple engineer:

So do not expose an NSManagedObjectContext* to more than one thread (actor, etc) under any circumstance. There is one ambiguity. You may pass the NSNotification* from the didSave notification to another thread's MOC's -mergeChangesFromContextDidSaveNotification: method.

Given that this post is over 3 years old now I would like to get a modern (iOS 7 and later) answer regarding the usage of NSManagedObjectContext's across threads. I have been accessing contexts across threads for a while now and have not run into any issues.

So does the performBlock method on NSManagedObjectContext obviate the need to use contexts on the thread they were created in or should I be re-engineering my applications to access the contexts inside of a serial queue?

Upvotes: 0

Views: 119

Answers (1)

Jody Hagins
Jody Hagins

Reputation: 28409

Most of the rule is still valid. However, the performBlock API takes care of that for you. As long as your access is always from within performBlock it will handle all of the serialization for you.

Upvotes: 0

Related Questions