How do you get a signal every time a UITextField text property changes in RxSwift
I had the same issues, apparently sweeper's answer did not work for me. So here is what I didWhen I set the text for textfield manually, I call sendActions method on the text field
textField.text = "Programmatically set text."textField.sendActions(for: .valueChanged)
On digging a little bit more, I realized that the rx.text
depends on UIControlEvents
and these are not triggered when you explicitly set the text.
Hope this helps
When you wish to observe a property of key-value observing compatible object, just call observe
!
Here is an example
textfield.rx.observe(String.self, "text").subscribe(onNext: { s in print(s ?? "nil")}).disposed(by: disposeBag)
This will detect changes to text
that are made by both the user and your code.
You can use this technique to not just observe text
, but also any other property that has a key path!