Created
April 1, 2019 09:55
-
-
Save Yoloabdo/96ff5240dcc00dccc88ee420f37a145f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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