Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //// Thread sync
- ////////////////////// CORE DATA ////////////////////////
- var mainManagedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.mainQueueConcurrencyType)
- mainManagedObjectContext.persistentStoreCoordinator = coordinator
- var backgroundManagedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.privateQueueConcurrencyType)
- backgroundManagedObjectContext.persistentStoreCoordinator = coordinator
- NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.handleMainCoreDataChangeInBackgroundManagedContext(notification:)), name: NSNotification.Name.NSManagedObjectContextDidSave, object: managedObjectContext)
- func handleMainCoreDataChangeInBackgroundManagedContext(notification: Notification){
- managedObjectContextBackgroundThread?.mergeChanges(fromContextDidSave: notification)
- }
- doSomeChanges()
- do {
- try managedObjectContext.save()
- }catch{
- print(“ERROR: Cound not save Core Data”)
- }
- }
- //////////////////// Realm ///////////////////////
- // сорян, но для синхронизации Realm код не нужен)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement