I have authorization controller with 2 UITextField properties and 1 UIButton. I want to bind my View to ViewModel but don\'t know how to to do it. This is my AuthorizatioVC.swi
The problem here is that you are trying to make your "viewModel" a class. It should be a function.
func viewModel(username: Observable, password: Observable, button: Observable) -> Observable {
return button
.withLatestFrom(Observable.combineLatest(login, password) { (login, password) })
.flatMap { login, password in
server.getAuthToken(withLogin: login, password: password)
}
.map { Auth(token: $0.token) }
Use set it up by doing this in your viewDidLoad:
let auth = viewModel(loginTxtField.rx_text, passwordTxtField.rx_text, button.rx_tap)
If you have multiple outputs for your view model, then it might be worth it to make a class (rather than returning a tuple from a function.) If you want to do that, then GithubSignupViewModel1
from the examples in the RxSwift repo is an excellent example of how to set it up.