Skip to content

Instantly share code, notes, and snippets.

@Yoloabdo
Created April 1, 2019 09:55
Show Gist options
  • Select an option

  • Save Yoloabdo/96ff5240dcc00dccc88ee420f37a145f to your computer and use it in GitHub Desktop.

Select an option

Save Yoloabdo/96ff5240dcc00dccc88ee420f37a145f to your computer and use it in GitHub Desktop.
class LoginViewController: UIViewController {
@IBOutlet weak var emailTextFeild: UITextField!
@IBOutlet weak var passwordTextFeild: UITextField!
@IBAction func userDidTapLogin(_ sender: UIButton) {
// validate user inputs
guard let email = emailTextFeild.text, !email.isEmpty else {
showErrorMessage(message: "No valid email is entered")
return
}
guard let password = passwordTextFeild.text, !email.isEmpty else {
showErrorMessage(message: "No valid password is entered")
return
}
// call network and verify login
var comp = URLComponents(string: "http://api.github.com/login")
comp?.queryItems = [URLQueryItem(name: "email", value: email), URLQueryItem(name: "password", value: password)]
URLSession.shared.dataTask(with: comp!.url!) {[weak self] (response, _, _) in
if response != nil {
self?.performSegue(withIdentifier: "moveToHome", sender: nil)
}
}
}
func showErrorMessage(message: String) {
// show error implementation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment