I know that you should abide by CoreData's thread confinement rules in general, but is it ever safe to use -[NSManagedObjectContext lock]
and friends? I know that accessing an NSManagedObject
property can trigger an implicit NSManagedObjectContext
fetch if the NSManagedObject
has unloaded properties, so I assume you would have to wrap all NSManagedObject
property accesses around -[NSManagedObjectContext lock]
and -[NSManagedObjectContext unlock]
. I thought this was the only gotcha. Are there others?
In the comments of this answer, Marcus Zarra says that I'm misinterpreting the documentation about -\[NSManagedObjectContext lock\]
and friends:
Sending this message to a managed object context helps the framework to understand the scope of a transaction in a multi-threaded environment. It is preferable to use the NSManagedObjectContext’s implementation of NSLocking instead using of a separate mutex object.
Also, the above quote implies that you can use other locks to guard NSManagedObjectContext
. Is this true?
I'm not worried about parent/child contexts for this question.