From 70a22322154330d1e7bbea82f49766999b478e3d Mon Sep 17 00:00:00 2001 From: woxtu Date: Wed, 21 Mar 2018 18:12:37 +0900 Subject: [PATCH] Add @discardableResult --- Sources/RouteKit/Navigator.swift | 12 ++++++++++-- Sources/RouteKit/Router.swift | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) 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"