Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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)")
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement