Hi there, I managed to get the undo for edit works with following code:
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if context != &KVOContext {
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
return
}
let oldValue = change?[.oldKey]
if let undo = self.undoManager {
undo.registerUndo(withTarget: object as! Employee) {
target in
target.setValue(oldValue, forKeyPath: keyPath!)
}
}
}
Just wonder is there any other solution for this. Thank you.
+Lee