diff --git a/Sources/RouteKit/Navigator.swift b/Sources/RouteKit/Navigator.swift index 588304c..397cebc 100644 --- a/Sources/RouteKit/Navigator.swift +++ b/Sources/RouteKit/Navigator.swift @@ -21,12 +21,16 @@ open class Navigator { self.router.append(route: route) } - open static func push(url: URL, animated: Bool) { + @discardableResult + open static func push(url: URL, animated: Bool) -> UIViewController? { if let viewController = self.router.push(url: url), let navigationController = self.rootViewController as? UINavigationController { navigationController.pushViewController(viewController, animated: animated) + return viewController + } else { + return nil } } @@ -36,9 +40,13 @@ open class Navigator { } } - open static func present(url: URL, animated: Bool, completion: (() -> Void)? = nil) { + @discardableResult + open static func present(url: URL, animated: Bool, completion: (() -> Void)? = nil) -> UIViewController? { if let viewController = self.router.push(url: url) { self.rootViewController?.present(viewController, animated: animated, completion: completion) + return viewController + } else { + return nil } } } diff --git a/Sources/RouteKit/Router.swift b/Sources/RouteKit/Router.swift index 0218d27..aba66e1 100644 --- a/Sources/RouteKit/Router.swift +++ b/Sources/RouteKit/Router.swift @@ -19,6 +19,7 @@ open class Router { self.routes.append(AnyRoute(route)) } + @discardableResult open func push(url: URL) -> T? { let queries = url.queryItems?.reduce(into: [:]) { result, item in result[item.name] = item.value ?? "true"