How to synchronize two independent NSManagedObjectContext in Core Data?

。_饼干妹妹 提交于 2019-12-13 17:18:15

问题


I have two NSManagedObjectContext which are independent: there is no relationship between the two. How to synchronize the two in Core Data?


回答1:


Yes you can do that if you are having two context like on is in background thread and other is on main thread for example then you can use

mergeChangesFromContextDidSaveNotification

to synchronize the data of two managed object context

// MARK: -
// MARK: Notification Handling
func managedObjectContextDidSave(notification: NSNotification) {
    dispatch_async(dispatch_get_main_queue()) { () -> Void in
        self.mainManagedObjectContext.mergeChangesFromContextDidSaveNotification(notification)
    }
}

You can refer whole tutorial here



来源:https://stackoverflow.com/questions/47903534/how-to-synchronize-two-independent-nsmanagedobjectcontext-in-core-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!