Skip to content

Instantly share code, notes, and snippets.

@Otbivnoe
Last active February 1, 2018 06:09
Show Gist options
  • Save Otbivnoe/7d4f35d048caeef89607e32303c58b06 to your computer and use it in GitHub Desktop.
Save Otbivnoe/7d4f35d048caeef89607e32303c58b06 to your computer and use it in GitHub Desktop.
Router
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