Is there anyway we can filter button tap event based on button title like below..!!
button.rx.tap
.filter { ($0.titleLabel.text.count)!> 0 }
Is there anyway we can filter button tap event based on button title like below..!!
button.rx.tap
.filter { ($0.titleLabel.text.count)!> 0 }
There may be a way to do it, but it isn't a correct thing to do. You programmatically changed the button title so the code that does that should be referenced here. Don't use your view as if it was a model.
For example:
func example(title: Observable<String>, button: UIButton, bag: DisposeBag) -> Observable<String> {
title
.bind(to: button.rx.title(for: .normal))
.disposed(by: bag)
return button.rx.tap
.withLatestFrom(title)
.filter { !$0.isEmpty }
}
Finally was able to do as below, not sure where its perfect or not but serve purpose though..!!!
button.rx.tap
.map(return button.titleLabel?.text!.lowercased()!)
.asDriver(onErrorJustReturn: "")
.drive(answerLabel.rx.text)
.disposed(by: bag)