Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.23 KB | None | 0 0
  1. //// Thread sync
  2.  
  3. ////////////////////// CORE DATA ////////////////////////
  4.  
  5. var mainManagedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.mainQueueConcurrencyType)
  6.         mainManagedObjectContext.persistentStoreCoordinator = coordinator
  7.  
  8. var backgroundManagedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.privateQueueConcurrencyType)
  9.         backgroundManagedObjectContext.persistentStoreCoordinator = coordinator
  10.  
  11.  NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.handleMainCoreDataChangeInBackgroundManagedContext(notification:)), name: NSNotification.Name.NSManagedObjectContextDidSave, object: managedObjectContext)
  12.  
  13. func handleMainCoreDataChangeInBackgroundManagedContext(notification: Notification){
  14.         managedObjectContextBackgroundThread?.mergeChanges(fromContextDidSave: notification)
  15.    }
  16.  
  17. doSomeChanges()
  18.  
  19.         do {
  20.             try managedObjectContext.save()
  21.         }catch{
  22.             print(“ERROR: Cound not save Core Data”)
  23.         }
  24.     }
  25.  
  26. //////////////////// Realm ///////////////////////
  27.  
  28. // сорян, но для синхронизации Realm код не нужен)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement