Created
May 31, 2017 14:49
-
-
Save Savchukv/b164ea08c3847d160c2b1f15a18411bc to your computer and use it in GitHub Desktop.
Example Login View Model with Firebase
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
// | |
// LoginViewModel.swift | |
// | |
// Created by Vasiliy Savchuk on 11/9/16. | |
// Copyright © 2016 All rights reserved. | |
// | |
// Usage this snippet: | |
// let viewModel: LoginViewModel = LoginViewModel() | |
// | |
// @IBAction func signInButtonDidPress(_ sender: Any) { | |
// self.viewModel.email = self.loginTextField.text?.trimmingCharacters(in:NSCharacterSet.whitespaces) | |
// self.viewModel.password = self.passwordTextField.text?.trimmingCharacters(in:NSCharacterSet.whitespaces) | |
// | |
// if self.viewModel.email != "" && self.viewModel.password != "" { | |
// self.viewModel.loginUser() | |
// } else { | |
// showAlert(title: "", message: "Please, enter your email and password") | |
// } | |
// } | |
import UIKit | |
import Firebase | |
import FirebaseAuth | |
class LoginViewModel: NSObject { | |
var email : String? | |
var password : String? | |
var completionHandler: ((FIRUser?, NSError?) -> Void)? | |
//MARK: Methods | |
func loginUser() { | |
FIRAuth.auth()?.signIn(withEmail: email!, password: password!, completion: { (user, error) in | |
if let handler = self.completionHandler { | |
handler(user, error as NSError?) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment