Skip to content

Instantly share code, notes, and snippets.

@dkw5877
Last active November 17, 2017 18:26
Show Gist options
  • Save dkw5877/285520538f39939f7f03f06981046c63 to your computer and use it in GitHub Desktop.
Save dkw5877/285520538f39939f7f03f06981046c63 to your computer and use it in GitHub Desktop.
Example of Authentication Coordinator Object
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