-
-
Save basilche/64c723dde6554620ba515f3215ed47e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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