Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. // Within the init: Create a background context child of main context
  2. backgroundContext = NSManagedObjectContext(concurrencyType: .
  3.  
  4. // MARK: - Batch processing in the background
  5. extension CoreDataStack{
  6. typealias Batch=(workerContext: NSManagedObjectContext) -> ()
  7.  
  8. func performBackgroundBatchOperation(batch: Batch){
  9.  
  10. backgroundContext.performBlock(){
  11. batch(workerContext: self.backgroundContext)
  12.  
  13. // Save it to the parent context, so normal saving
  14. // can work
  15. do{
  16. try self.backgroundContext.save()
  17. }catch{
  18. fatalError("Error while saving backgroundContext: \(error)")
  19. }
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement