Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSManagedObjectContext concurrency

In the documentation: NSManagedObjectContext Class Reference it states:

Setter methods on queue-based managed object contexts are thread-safe. You can invoke these methods directly on any thread.

Can someone give a code example of what exactly this means. Does it actually mean to read "Setter methods on queue-based managed OBJECTS are thread-safe"

Also, if I have a managed object stored as an iVar (not best practice), can I called it's managedObjectContext method and its and then call performBlock() on this safely from within any thread?

like image 487
bandejapaisa Avatar asked Oct 29 '25 16:10

bandejapaisa


1 Answers

No, it means exactly what it says. You can call setter methods on a NSManagedObjectContext from any thread. eg: -[setParentContext:], -[setPersistentStoreCoordinator:].

You can call -[performBlock:]and -[performBlockAndWait:] from any thread as it will execute the passed block on the context's queue.

like image 58
Stephen Groom Avatar answered Oct 31 '25 06:10

Stephen Groom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!