Skip to content

Instantly share code, notes, and snippets.

@catalinaturlea
Created September 25, 2019 18:56
Show Gist options
  • Save catalinaturlea/2d44dbc22af21cb6022c7e67639edaa3 to your computer and use it in GitHub Desktop.
Save catalinaturlea/2d44dbc22af21cb6022c7e67639edaa3 to your computer and use it in GitHub Desktop.
ViewController-version1
class ViewController: UIViewController {
// ....
@IBAction func loginButtonPressed() {
login(emailTextField.text ?? "", passwordTextField.text ?? "", completion: { success in
if !success {
showLoginError()
return
}
goToApp()
})
}
func login(email: String, password: String, completion: ((Bool) -> Void)) {
if email.isEmpty {
completion(false)
} else if !isValidEmail(email) {
completion(false)
}
if password.isEmpty {
completion(false)
}
UserService.shared.login(email, password, completion: { (success, error) in
if success {
completion(true)
}
completion(false)
})
}
// ....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment