2

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.

鸡肉味嘎嘣脆
  • 233
  • 1
  • 3
  • 15
  • Duplicate of [how to use kvo to observer textfiled's text change?](https://stackoverflow.com/questions/35858831/how-to-use-kvo-to-observer-textfileds-text-change?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – Willeke May 31 '18 at 11:19

0 Answers0