Reputation: 4631
I want to observe any change of the UITextField.text
property using RxSwift.
I trying to use rx.text
property, but it called only when I set text
property like this: textField.text = ""
, but not working when I typing text.
Also I tried to use rx.observe(String.self, "text")
, but it gives the same result.
How can I observe any change of the text in UITextField?
Upvotes: 2
Views: 3127
Reputation: 266
To observe any change of the text in UITextField
you can create extension for Reactive
class:
public extension Reactive where Base: UITextField {
public var textChange: Observable<String?> {
return Observable.merge(self.base.rx.observe(String.self, "text"),
self.base.rx.controlEvent(.editingChanged).withLatestFrom(self.base.rx.text))
}
}
Upvotes: 11