I am trying to create an Observable that outputs a value based on the value of a variable.
Something like that:
let fullName = Variable<String>("") let isFullNameOKObs: Observable<Bool> isFullNameOKObs = fullName .asObservable() .map { (val) -> Bool in // here business code to determine if the fullName is 'OK' let ok = val.characters.count >= 3 return ok }
Unfortunately, the block in the func function is never called!
The reason for this is that:
- The fullName variable is bound to a UITextField with the bidirectional operator ↔, as defined in the RxSwift example.
- It is observed that isFullNameOKObs Observable will hide or display the submit button of my ViewController.
Any help would be greatly appreciated.
thanks
Model
class Model { let fullName = Variable<String>("") let isFullNameOKObs: Observable<Bool> let disposeBag = DisposeBag() init(){ isFullNameOKObs = fullName .asObservable() .debug("isFullNameOKObs") .map { (val) -> Bool in let ok = val.characters.count >= 3 return ok } .debug("isFullNameOKObs") isRegFormOKObs = Observable.combineLatest( isFullNameOKObs, is...OK, ... ) { $0 && $1 && ... } isRegFormOKObs .debug("isRegFormOKObs") .asObservable() .subscribe { (event) in
ViewController:
func bindModel() -> Void { _ = txFullName.rx.textInput <-> model!.fullName ...... }
ios swift observable rx-swift
t4ncr3d3
source share