Concurrency with multiple managedObjectContexts as in Chapter 10

In the chapter 10 of the book, I see two ways for reaching concurrency using multiple managedObjectContexts.
What’s confusing to me is that in the examples, two approaches are used

let privateContext = NSManagedObjectContext( concurrencyType: .PrivateQueueConcurrencyType)
privateContext.persistentStoreCoordinator = coreDataStack.context.persistentStoreCoordinator
// 2
privateContext.performBlock { () → Void in // 3
let results: [AnyObject] do {
results = try self.coreDataStack.context .executeFetchRequest(self.surfJournalFetchRequest())
} catch {
let nserror = error as NSError print(“ERROR: (nserror)”) results =
}

and

// 1
let childContext = NSManagedObjectContext( concurrencyType: .MainQueueConcurrencyType)
childContext.parentContext = coreDataStack.context
// 2
let childEntry = childContext.objectWithID( surfJournalEntry.objectID) as! JournalEntry
// 3
detailViewController.journalEntry = childEntry detailViewController.context = childContext detailViewController.delegate = self

Why is either of them used? And why in the second one, the childContext is declared on the MainQueue?

1 Like