Last active
November 17, 2017 18:26
-
-
Save dkw5877/285520538f39939f7f03f06981046c63 to your computer and use it in GitHub Desktop.
Example of Authentication Coordinator Object
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 | |
protocol AuthenticationCoordinatorDelegate:class { | |
func coordinatorDidAuthenticate(coordinator:AuthenticationCoordinator) | |
} | |
class AuthenticationCoordinator:Coordinator { | |
weak var delegate:AuthenticationCoordinatorDelegate? | |
let navigationController:UINavigationController | |
let loginViewController:LoginViewController | |
init(navigationController:UINavigationController) { | |
self.navigationController = navigationController | |
self.loginViewController = LoginViewController() | |
} | |
deinit { | |
print("deallocing \(self)") | |
} | |
func start() { | |
showLoginViewController() | |
} | |
func showLoginViewController() { | |
loginViewController.delegate = self | |
navigationController.show(loginViewController, sender: self) | |
} | |
func showSignupViewController(){ | |
let signup = SignupViewController() | |
signup.delegate = self | |
navigationController.show(signup, sender: self) | |
} | |
func showPasswordViewController(){ | |
let password = PasswordViewController() | |
password.delegate = self | |
navigationController.show(password, sender: self) | |
} | |
} | |
extension AuthenticationCoordinator : LoginViewControllerDelegate { | |
func didSuccessfullyLogin() { | |
print(navigationController.childViewControllers) | |
delegate?.coordinatorDidAuthenticate(coordinator: self) | |
} | |
func didChooseSignup() { | |
showSignupViewController() | |
} | |
} | |
extension AuthenticationCoordinator : SignupViewControllerDelegate { | |
func didCompleteSignup() { | |
showPasswordViewController() | |
} | |
} | |
extension AuthenticationCoordinator : PasswordViewControllerDelegate { | |
func didSignupWithEmailAndPassword(email: String, passowrd: String) { | |
delegate?.coordinatorDidAuthenticate(coordinator: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment