Skip to content

Instantly share code, notes, and snippets.

@basilche
Created July 9, 2019 04:46
Show Gist options
  • Save basilche/64c723dde6554620ba515f3215ed47e2 to your computer and use it in GitHub Desktop.
Save basilche/64c723dde6554620ba515f3215ed47e2 to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var loginTextField: UITextField?
@IBOutlet weak var passwordTextField: UITextField?
@IBOutlet weak var loginButton: UIButton?
override func viewDidLoad() {
super.viewDidLoad()
loginButton?.isEnabled = false
}
@IBAction func loginChanged(_ sender: UITextField) {
handleInput(login: sender.text ?? "", password: passwordTextField?.text ?? "")
}
@IBAction func passwordChanged(_ sender: UITextField) {
handleInput(login: loginTextField?.text ?? "", password: sender.text ?? "")
}
func handleInput(login: String, password: String) {
loginButton?.isEnabled = login.isLoginValid && password.isPasswordValid
}
}
extension String {
var isLoginValid: Bool {
return self.count > 0
}
var isPasswordValid: Bool {
return self.count > 5
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment