How do you get a signal every time a UITextField text property changes in RxSwift

前端 未结 4 1832
挽巷
挽巷 2021-02-18 23:36

How do you get a signal from programmatically made changes to UITextField text property? By using rx.text only reports a signal when the user input the text by keyboard. If you

4条回答
  •  感动是毒
    2021-02-19 00:03

    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!

提交回复
热议问题