Regarding parent contexts, unfortunately, the last time I checked the documentation was pretty Spartan, and on the Internet you will find that almost everyone turned the thread upside down. In 2011, there was one WWDC session on master data or so, where everything was clear, and if you carefully study the API, it will start to make sense.
The child is not a context background - this is the main context. A child is a context with which you usually communicate. Parent is the background context.
The child drags the changes to the parent. This is why the parent has a persistentStoreCoordinator, but the child instead has a parentContext (he does NOT need a constant StoreCoordinator).
So, your main context is in the main (UI) queue. He saves the changes to his parent. This happens in memory (quickly - leaving the user interface as responsive as possible).
The parent context then saves its changes to the persist store through its persistentStoreCoordinator. This is why the parent is in a private queue.
lazy var managedObjectContext: NSManagedObjectContext = { let parentContext = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType) parentContext.persistentStoreCoordinator = self.persistentStoreCoordinator let managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType) managedObjectContext.parentContext = parentContext return managedObjectContext }()
There are other optimizations, such as installing .undoManager on nil, but this general architecture works flawlessly to preserve the background.
You probably also want to add a save method that gets the block / close completion, immediately saving your child queue (which only saves in the parent, as mentioned), then calls the parentContext executeBlock method in which you will have it save (in its private queue) to the underlying persistent storage (relatively slow, but now non-blocking), and then calls your completion / closing block (which you either configured with the GCD to run in the main queue, or else you go to the main queue ttuda in the parent method executeBlock.
Everything falls into place perfectly when you do not invert the architecture. I am not sure how it is launched on the network, but this is almost a universal error.
Good luck.