Slide 24
Slide 24 text
final class LoginViewController: UIViewController {
private let dispatch: (Action) -> Void
init (dispatch: @escaping (Action) -> Void) {
super.init(nibName: nil, bundle: nil)
self.dispatch = dispatch
}
// ...
override func viewDidLoad() {
super.viewDidLoad()
loginButton.addTarget(self,
action: #selector(performLogin(_:)),
for: .touchUpInside
)
}
@objc private func performLogin(_ sender: UIButton) {
let validation = LoginValidation(
login: loginTextField.text,
password: passwordTextField.text
)
switch validation {
case let .success(login, password):
dispatch(LoginAction.perform(login: login, password: password))
case let .failed(error):
interpret(validationError: error)
}
}
}