问题
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