Last active
February 1, 2018 06:09
-
-
Save Otbivnoe/7d4f35d048caeef89607e32303c58b06 to your computer and use it in GitHub Desktop.
Router
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
protocol Closable: class { | |
func close() | |
} | |
protocol RouterProtocol: class { | |
associatedtype V: UIViewController | |
weak var viewController: V? { get } | |
func open(_ viewController: UIViewController, transition: Transition) | |
} | |
class Router<U>: RouterProtocol, Closable where U: UIViewController { | |
typealias V = U | |
weak var viewController: V? | |
var openTransition: Transition? | |
func open(_ viewController: UIViewController, transition: Transition) { | |
transition.viewController = self.viewController | |
transition.open(viewController) | |
} | |
func close() { | |
guard let openTransition = openTransition else { | |
assertionFailure("You should specify an open transition in order to close a module.") | |
return | |
} | |
guard let viewController = viewController else { | |
assertionFailure("Nothing to close.") | |
return | |
} | |
openTransition.close(viewController) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment