Created
May 3, 2016 18:38
-
-
Save frr149/febf3a06c40e7de363b192c04dabfef9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Within the init: Create a background context child of main context | |
backgroundContext = NSManagedObjectContext(concurrencyType: . | |
// MARK: - Batch processing in the background | |
extension CoreDataStack{ | |
typealias Batch=(workerContext: NSManagedObjectContext) -> () | |
func performBackgroundBatchOperation(batch: Batch){ | |
backgroundContext.performBlock(){ | |
batch(workerContext: self.backgroundContext) | |
// Save it to the parent context, so normal saving | |
// can work | |
do{ | |
try self.backgroundContext.save() | |
}catch{ | |
fatalError("Error while saving backgroundContext: \(error)") | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment