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

前端 未结 4 1783
挽巷
挽巷 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-18 23:46

    You can add controlEvents to asObservable:

        textField.rx.controlEvent([.editingChanged])
            .asObservable().subscribe({ [unowned self] _ in
                print("My text : \(self.textField.text ?? "")")
            }).disposed(by: bag)
    

提交回复
热议问题