Last active
February 13, 2019 14:21
-
-
Save morpheby/1df592b04ec4b5cd8dfaa2931b351cdc to your computer and use it in GitHub Desktop.
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
public protocol Router { | |
associatedtype ViewController: UIViewController | |
/// Returns view controller that is managing the view | |
/// presented by the router | |
var viewController: ViewController? { get } | |
} | |
extension Router { | |
func wireNextRouter<T: Router>(_ wireClosure: @escaping (T.ViewController) throws -> T, file: StaticString = #file, line: UInt = #line) -> (UIViewController) -> Void { | |
return { (targetViewController: UIViewController) -> Void in | |
guard let target = targetViewController as? T.ViewController else { | |
fatalError("Invalid target invoked: Should be \(T.ViewController.self), is \(type(of: targetViewController))", file: file, line: line) | |
} | |
do { | |
_ = try wireClosure(target) | |
} catch let error { | |
fatalError("Error while instantiating \(T.self) at \(file):\(line): \(error)", file: file, line: line) | |
} | |
} | |
} | |
func wireEmpty() -> (UIViewController) -> Void { | |
return { (targetViewController: UIViewController) -> Void in | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment