I want to ovserve a UITextField
value change. In Swift 4 it's prefer to use block based KVO API. So I got this code:
self.kvo = self.textField.observe(\.text, options: [.new, .old], changeHandler: { (textField, change) in
print(change.newValue)
print(change.oldValue)
})
The block was called when editing ended, not text value changed. How could I do to observe the UITextField
value changed?
I know that addTarget
could detect editing changed. But I want to know both old value and new value when editing changed. And I don't want to use an additional variable to record the old value. KVO could do this but It seems not be called when editing changed.