Sorry. I am confused what is binding in Rxswift. As far as I know, observable
won't produce value unless a observer subscribed on it, e.g myObservable.subscribe(onNext: {})
.
But when I read the follow line of code:
// in LoginViewModel.swift
init() {
isValid = Observable.combineLatest(username.asObservable(), password.asObservable()) { (username, password) in
return !username.isEmpty && !password.isEmpty
}
}
// in LoginViewController.swift
viewModel.isValid.bind(to: loginButton.rx.isEnabled).disposed(by: disposeBag)
I am confused here why the isValid
Observable is able to be observed without calling a subscribe
method on it?
Why we can just call bind(to:) in LoginViewController.swift
without calling something like viewModel.isValid.subscribe(...)