Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updated core data concurrency documentation?

Tags:

The only (and most recent) results I'm finding about best practices are here: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdConcurrency.html

However, the very top of the page says,

"Important: Best practices for concurrency with Core Data have changed dramatically since this document was written; please note that this chapter does not represent current recommendations."

Where can I find more current documentation for concurrency with core data?

like image 338
user3781236 Avatar asked Sep 23 '14 22:09

user3781236


People also ask

Is Managedobjectcontext thread safe?

Managed Object ContextThe NSManagedObjectContext class isn't thread safe. Plain and simple. You should never share managed object contexts between threads. This is a hard rule you shouldn't break.

Is Core Data thread safe a NSManagedObjectID?

functions are thread safe and can be called from other threads. A NSManagedObject cannot be shared across threads. A NSManagedObjectID can be shared across threads. Changes from one NSManagedObjectContext can be merged into another NSManagedObjectContext , even on another thread.

Is Core Data a Threadsafe?

Core Data is designed to work in a multithreaded environment. However, not every object under the Core Data framework is thread safe. To use Core Data in a multithreaded environment, ensure that: Managed object contexts are bound to the thread (queue) that they are associated with upon initialization.

What is NSPersistentStoreCoordinator in iOS?

A persistent store coordinator is an instance of NSPersistentStoreCoordinator . It has a reference to a managed object model that describes the entities in the store or stores it manages. The coordinator is the central object in a Core Data stack.


2 Answers

The best discussion is now under 'Concurrency' within the NSManagedObjectContext documentation.

My summary:

Thread confinement is still required. The big changes introduced by iOS 5/OS X v10.7 were that contexts can now have other contexts as parents and can manage their own serial queues.

Changes are automatically migrated from children to parent upon a save. That's now what save means. Only if your parent is the persistent store are you actually committing to disk.

So all that stuff about synchronising by notifications is what Apple doesn't want you to follow. All of those mechanisms are still available but Apple has pulled the most common patterns directly into the framework.

like image 146
Tommy Avatar answered Oct 26 '22 13:10

Tommy


The Core Data Programming Guide has been updated for iOS 9/OS X El Capitan. See https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Conceptual/CoreData/Concurrency.html.

I also found WWDC 2014 session 225 What's new in Core Data (at 22:50) very helpful in understanding both current and historic concurrency methods.

like image 40
stefanlindbohm Avatar answered Oct 26 '22 12:10

stefanlindbohm