From 44f3c8d1050b702644dccc735dabf1b41120463a Mon Sep 17 00:00:00 2001 From: Paul Kraft Date: Mon, 1 May 2023 12:26:30 +0200 Subject: [PATCH 1/5] Adapt app to work with 3.0.0 release --- .../project.pbxproj | 21 +------ .../xcshareddata/swiftpm/Package.resolved | 60 +++++++++---------- XCoordinator-Example/Common/AppDelegate.swift | 3 +- .../Coordinators/AboutCoordinator.swift | 2 +- .../Coordinators/AppCoordinator.swift | 22 +++---- .../Coordinators/HomePageCoordinator.swift | 8 +-- .../Coordinators/HomeSplitCoordinator.swift | 10 ++-- .../Coordinators/HomeTabCoordinator.swift | 10 ++-- .../Coordinators/NewsCoordinator.swift | 2 +- .../Coordinators/UserCoordinator.swift | 2 +- .../Coordinators/UserListCoordinator.swift | 4 +- .../Scenes/About/AboutViewModelImpl.swift | 6 +- .../Scenes/Home/HomeViewModelImpl.swift | 10 ++-- .../Scenes/Login/LoginViewModelImpl.swift | 6 +- .../Scenes/News/NewsViewModelImpl.swift | 6 +- .../Scenes/User/UserViewModelImpl.swift | 8 +-- .../Scenes/UserList/UsersViewModelImpl.swift | 6 +- 17 files changed, 83 insertions(+), 103 deletions(-) diff --git a/XCoordinator-Example.xcodeproj/project.pbxproj b/XCoordinator-Example.xcodeproj/project.pbxproj index 10a4ee7..ca7700d 100644 --- a/XCoordinator-Example.xcodeproj/project.pbxproj +++ b/XCoordinator-Example.xcodeproj/project.pbxproj @@ -57,7 +57,6 @@ 9B5657D42315FB3500F4F4F7 /* TransitionAnimation+Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5657A42315FB3500F4F4F7 /* TransitionAnimation+Defaults.swift */; }; 9B5657D62315FB3500F4F4F7 /* CGAffineTransform+InPlace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5657A62315FB3500F4F4F7 /* CGAffineTransform+InPlace.swift */; }; 9B5657D92315FB9700F4F4F7 /* Action in Frameworks */ = {isa = PBXBuildFile; productRef = 9B5657D82315FB9700F4F4F7 /* Action */; }; - 9B5657DC2315FC1000F4F4F7 /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 9B5657DB2315FC1000F4F4F7 /* RxCocoa */; }; 9BD3EBF42330CE46005861BF /* Transitions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BD3EBF32330CE46005861BF /* Transitions.swift */; }; 9BD3EBFD2330D84F005861BF /* XCText+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BD3EBF62330D84E005861BF /* XCText+Extras.swift */; }; 9BD3EBFE2330D84F005861BF /* XCTestManifests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BD3EBF72330D84F005861BF /* XCTestManifests.swift */; }; @@ -167,7 +166,6 @@ buildActionMask = 2147483647; files = ( 9B0A753A2316C1810092CA3A /* XCoordinatorRx in Frameworks */, - 9B5657DC2315FC1000F4F4F7 /* RxCocoa in Frameworks */, 9B5657D92315FB9700F4F4F7 /* Action in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -449,7 +447,6 @@ name = "XCoordinator-Example"; packageProductDependencies = ( 9B5657D82315FB9700F4F4F7 /* Action */, - 9B5657DB2315FC1000F4F4F7 /* RxCocoa */, 9B0A75392316C1810092CA3A /* XCoordinatorRx */, ); productName = "XCoordinator-Example"; @@ -526,7 +523,6 @@ mainGroup = 9B56572C2315FA7B00F4F4F7; packageReferences = ( 9B5657D72315FB9700F4F4F7 /* XCRemoteSwiftPackageReference "Action" */, - 9B5657DA2315FC1000F4F4F7 /* XCRemoteSwiftPackageReference "RxSwift" */, 9B5657DD2315FC5C00F4F4F7 /* XCRemoteSwiftPackageReference "XCoordinator" */, ); productRefGroup = 9B5657362315FA7B00F4F4F7 /* Products */; @@ -956,20 +952,12 @@ minimumVersion = 4.0.1; }; }; - 9B5657DA2315FC1000F4F4F7 /* XCRemoteSwiftPackageReference "RxSwift" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/ReactiveX/RxSwift.git"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 5.0.1; - }; - }; 9B5657DD2315FC5C00F4F4F7 /* XCRemoteSwiftPackageReference "XCoordinator" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/quickbirdstudios/XCoordinator.git"; requirement = { - kind = upToNextMajorVersion; - minimumVersion = 2.0.2; + branch = feature/3.0.0; + kind = branch; }; }; /* End XCRemoteSwiftPackageReference section */ @@ -985,11 +973,6 @@ package = 9B5657D72315FB9700F4F4F7 /* XCRemoteSwiftPackageReference "Action" */; productName = Action; }; - 9B5657DB2315FC1000F4F4F7 /* RxCocoa */ = { - isa = XCSwiftPackageProductDependency; - package = 9B5657DA2315FC1000F4F4F7 /* XCRemoteSwiftPackageReference "RxSwift" */; - productName = RxCocoa; - }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 9B56572D2315FA7B00F4F4F7 /* Project object */; diff --git a/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 2f97f0c..f0966d2 100644 --- a/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,34 +1,32 @@ { - "object": { - "pins": [ - { - "package": "Action", - "repositoryURL": "https://github.com/RxSwiftCommunity/Action.git", - "state": { - "branch": null, - "revision": "cdade63f7bbe1f5e1eff7779e5858a796dc2c001", - "version": "4.0.1" - } - }, - { - "package": "RxSwift", - "repositoryURL": "https://github.com/ReactiveX/RxSwift.git", - "state": { - "branch": null, - "revision": "b3e888b4972d9bc76495dd74d30a8c7fad4b9395", - "version": "5.0.1" - } - }, - { - "package": "XCoordinator", - "repositoryURL": "https://github.com/quickbirdstudios/XCoordinator.git", - "state": { - "branch": null, - "revision": "0c16cc7061f93d278279137277efb13385e960a6", - "version": "2.0.5" - } + "pins" : [ + { + "identity" : "action", + "kind" : "remoteSourceControl", + "location" : "https://github.com/RxSwiftCommunity/Action.git", + "state" : { + "revision" : "21110e93ef7b08ce9f01806827e4f381b5b09ab1", + "version" : "4.3.0" } - ] - }, - "version": 1 + }, + { + "identity" : "rxswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/ReactiveX/RxSwift.git", + "state" : { + "revision" : "b4307ba0b6425c0ba4178e138799946c3da594f8", + "version" : "6.5.0" + } + }, + { + "identity" : "xcoordinator", + "kind" : "remoteSourceControl", + "location" : "https://github.com/quickbirdstudios/XCoordinator.git", + "state" : { + "branch" : "feature/3.0.0", + "revision" : "e5ab085bbd758cb6edaa265b62bd2a8ea318c093" + } + } + ], + "version" : 2 } diff --git a/XCoordinator-Example/Common/AppDelegate.swift b/XCoordinator-Example/Common/AppDelegate.swift index 0db0077..9b54e3c 100644 --- a/XCoordinator-Example/Common/AppDelegate.swift +++ b/XCoordinator-Example/Common/AppDelegate.swift @@ -7,6 +7,7 @@ // import UIKit +import XCoordinator @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -14,7 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // MARK: Stored properties private lazy var mainWindow = UIWindow() - private let router = AppCoordinator().strongRouter + private let router: any Router = AppCoordinator() // MARK: UIApplicationDelegate diff --git a/XCoordinator-Example/Coordinators/AboutCoordinator.swift b/XCoordinator-Example/Coordinators/AboutCoordinator.swift index 2a39280..f05737b 100644 --- a/XCoordinator-Example/Coordinators/AboutCoordinator.swift +++ b/XCoordinator-Example/Coordinators/AboutCoordinator.swift @@ -29,7 +29,7 @@ class AboutCoordinator: NavigationCoordinator { switch route { case .home: let viewController = AboutViewController() - let viewModel = AboutViewModelImpl(router: unownedRouter) + let viewModel = AboutViewModelImpl(router: self) viewController.bind(to: viewModel) return .push(viewController) case .website: diff --git a/XCoordinator-Example/Coordinators/AppCoordinator.swift b/XCoordinator-Example/Coordinators/AppCoordinator.swift index a1b356c..33d835e 100644 --- a/XCoordinator-Example/Coordinators/AppCoordinator.swift +++ b/XCoordinator-Example/Coordinators/AppCoordinator.swift @@ -11,7 +11,7 @@ import XCoordinator enum AppRoute: Route { case login - case home(StrongRouter?) + case home((any Presentable)?) case newsDetail(News) } @@ -29,11 +29,11 @@ class AppCoordinator: NavigationCoordinator { switch route { case .login: let viewController = LoginViewController.instantiateFromNib() - let viewModel = LoginViewModelImpl(router: unownedRouter) + let viewModel = LoginViewModelImpl(router: self) viewController.bind(to: viewModel) return .push(viewController) case let .home(router): - if let router = router { + if let router { return .presentFullScreen(router, animation: .fade) } let alert = UIAlertController( @@ -42,25 +42,25 @@ class AppCoordinator: NavigationCoordinator { preferredStyle: .alert) alert.addAction( .init(title: "\(HomeTabCoordinator.self)", style: .default) { [unowned self] _ in - self.trigger(.home(HomeTabCoordinator().strongRouter)) + self.trigger(.home(HomeTabCoordinator())) } ) alert.addAction( .init(title: "\(HomeSplitCoordinator.self)", style: .default) { [unowned self] _ in - self.trigger(.home(HomeSplitCoordinator().strongRouter)) + self.trigger(.home(HomeSplitCoordinator())) } ) alert.addAction( .init(title: "\(HomePageCoordinator.self)", style: .default) { [unowned self] _ in - self.trigger(.home(HomePageCoordinator().strongRouter)) + self.trigger(.home(HomePageCoordinator())) } ) alert.addAction( .init(title: "Random", style: .default) { [unowned self] _ in - let routers: [() -> StrongRouter] = [ - { HomeTabCoordinator().strongRouter }, - { HomeSplitCoordinator().strongRouter }, - { HomeTabCoordinator().strongRouter } + let routers: [() -> any Presentable] = [ + { HomeTabCoordinator() }, + { HomeSplitCoordinator() }, + { HomeTabCoordinator() } ] let router = routers.randomElement().map { $0() } self.trigger(.home(router)) @@ -71,7 +71,7 @@ class AppCoordinator: NavigationCoordinator { return .multiple( .dismissAll(), .popToRoot(), - deepLink(AppRoute.home(HomePageCoordinator().strongRouter), + deepLink(AppRoute.home(HomePageCoordinator()), HomeRoute.news, NewsRoute.newsDetail(news)) ) diff --git a/XCoordinator-Example/Coordinators/HomePageCoordinator.swift b/XCoordinator-Example/Coordinators/HomePageCoordinator.swift index da623b5..5144c0f 100644 --- a/XCoordinator-Example/Coordinators/HomePageCoordinator.swift +++ b/XCoordinator-Example/Coordinators/HomePageCoordinator.swift @@ -12,13 +12,13 @@ class HomePageCoordinator: PageCoordinator { // MARK: Stored properties - private let newsRouter: StrongRouter - private let userListRouter: StrongRouter + private let newsRouter: any Presentable + private let userListRouter: any Presentable // MARK: Initialization - init(newsRouter: StrongRouter = NewsCoordinator().strongRouter, - userListRouter: StrongRouter = UserListCoordinator().strongRouter) { + init(newsRouter: any Presentable = NewsCoordinator(), + userListRouter: any Presentable = UserListCoordinator()) { self.newsRouter = newsRouter self.userListRouter = userListRouter diff --git a/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift b/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift index 290620f..4c97009 100644 --- a/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift +++ b/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift @@ -12,17 +12,17 @@ class HomeSplitCoordinator: SplitCoordinator { // MARK: Stored properties - private let newsRouter: StrongRouter - private let userListRouter: StrongRouter + private let newsRouter: any Presentable + private let userListRouter: any Presentable // MARK: Initialization - init(newsRouter: StrongRouter = NewsCoordinator().strongRouter, - userListRouter: StrongRouter = UserListCoordinator().strongRouter) { + init(newsRouter: any Presentable = NewsCoordinator(), + userListRouter: any Presentable = UserListCoordinator()) { self.newsRouter = newsRouter self.userListRouter = userListRouter - super.init(master: userListRouter, detail: newsRouter) + super.init(primary: userListRouter, secondary: newsRouter) } // MARK: Overrides diff --git a/XCoordinator-Example/Coordinators/HomeTabCoordinator.swift b/XCoordinator-Example/Coordinators/HomeTabCoordinator.swift index 377fb98..ccdf199 100644 --- a/XCoordinator-Example/Coordinators/HomeTabCoordinator.swift +++ b/XCoordinator-Example/Coordinators/HomeTabCoordinator.swift @@ -18,8 +18,8 @@ class HomeTabCoordinator: TabBarCoordinator { // MARK: Stored properties - private let newsRouter: StrongRouter - private let userListRouter: StrongRouter + private let newsRouter: any Presentable + private let userListRouter: any Presentable // MARK: Initialization @@ -30,12 +30,10 @@ class HomeTabCoordinator: TabBarCoordinator { let userListCoordinator = UserListCoordinator() userListCoordinator.rootViewController.tabBarItem = UITabBarItem(tabBarSystemItem: .more, tag: 1) - self.init(newsRouter: newsCoordinator.strongRouter, - userListRouter: userListCoordinator.strongRouter) + self.init(newsRouter: newsCoordinator, userListRouter: userListCoordinator) } - init(newsRouter: StrongRouter, - userListRouter: StrongRouter) { + init(newsRouter: any Presentable, userListRouter: any Presentable) { self.newsRouter = newsRouter self.userListRouter = userListRouter diff --git a/XCoordinator-Example/Coordinators/NewsCoordinator.swift b/XCoordinator-Example/Coordinators/NewsCoordinator.swift index 8429d61..4599929 100644 --- a/XCoordinator-Example/Coordinators/NewsCoordinator.swift +++ b/XCoordinator-Example/Coordinators/NewsCoordinator.swift @@ -29,7 +29,7 @@ class NewsCoordinator: NavigationCoordinator { case .news: let viewController = NewsViewController.instantiateFromNib() let service = MockNewsService() - let viewModel = NewsViewModelImpl(newsService: service, router: unownedRouter) + let viewModel = NewsViewModelImpl(newsService: service, router: self) viewController.bind(to: viewModel) return .push(viewController) case .newsDetail(let news): diff --git a/XCoordinator-Example/Coordinators/UserCoordinator.swift b/XCoordinator-Example/Coordinators/UserCoordinator.swift index d6f6947..06eda27 100644 --- a/XCoordinator-Example/Coordinators/UserCoordinator.swift +++ b/XCoordinator-Example/Coordinators/UserCoordinator.swift @@ -34,7 +34,7 @@ class UserCoordinator: NavigationCoordinator { return .push(viewController, animation: .fade) case let .user(username): let viewController = UserViewController.instantiateFromNib() - let viewModel = UserViewModelImpl(router: unownedRouter, username: username) + let viewModel = UserViewModelImpl(router: self, username: username) viewController.bind(to: viewModel) return .push(viewController) case let .alert(title, message): diff --git a/XCoordinator-Example/Coordinators/UserListCoordinator.swift b/XCoordinator-Example/Coordinators/UserListCoordinator.swift index 6d44a92..026d512 100644 --- a/XCoordinator-Example/Coordinators/UserListCoordinator.swift +++ b/XCoordinator-Example/Coordinators/UserListCoordinator.swift @@ -31,12 +31,12 @@ class UserListCoordinator: NavigationCoordinator { switch route { case .home: let viewController = HomeViewController.instantiateFromNib() - let viewModel = HomeViewModelImpl(router: unownedRouter) + let viewModel = HomeViewModelImpl(router: self) viewController.bind(to: viewModel) return .push(viewController) case .users: let viewController = UsersViewController.instantiateFromNib() - let viewModel = UsersViewModelImpl(userService: MockUserService(), router: unownedRouter) + let viewModel = UsersViewModelImpl(userService: MockUserService(), router: self) viewController.bind(to: viewModel) return .push(viewController, animation: .fade) case .user(let username): diff --git a/XCoordinator-Example/Scenes/About/AboutViewModelImpl.swift b/XCoordinator-Example/Scenes/About/AboutViewModelImpl.swift index 1b74f7f..94e49ef 100644 --- a/XCoordinator-Example/Scenes/About/AboutViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/About/AboutViewModelImpl.swift @@ -20,7 +20,7 @@ class AboutViewModelImpl: AboutViewModel, AboutViewModelInput, AboutViewModelOut // MARK: Actions private lazy var openWebsiteAction = CocoaAction { [unowned self] in - self.router.rx.trigger(.website) + self.router.rxTrigger(.website) } // MARK: Outputs @@ -29,11 +29,11 @@ class AboutViewModelImpl: AboutViewModel, AboutViewModelInput, AboutViewModelOut // MARK: Stored properties - private let router: UnownedRouter + private unowned let router: any Router // MARK: Initialization - init(router: UnownedRouter) { + init(router: any Router) { self.router = router } diff --git a/XCoordinator-Example/Scenes/Home/HomeViewModelImpl.swift b/XCoordinator-Example/Scenes/Home/HomeViewModelImpl.swift index 13759fa..68f074f 100644 --- a/XCoordinator-Example/Scenes/Home/HomeViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/Home/HomeViewModelImpl.swift @@ -22,23 +22,23 @@ class HomeViewModelImpl: HomeViewModel, HomeViewModelInput, HomeViewModelOutput // MARK: Actions private lazy var logoutAction = CocoaAction { [unowned self] in - self.router.rx.trigger(.logout) + self.router.rxTrigger(.logout) } private lazy var usersAction = CocoaAction { [unowned self] in - self.router.rx.trigger(.users) + self.router.rxTrigger(.users) } private lazy var aboutAction = CocoaAction { [unowned self] in - self.router.rx.trigger(.about) + self.router.rxTrigger(.about) } // MARK: Stored properties - private let router: UnownedRouter + private unowned let router: any Router // MARK: Initialization - init(router: UnownedRouter) { + init(router: any Router) { self.router = router } diff --git a/XCoordinator-Example/Scenes/Login/LoginViewModelImpl.swift b/XCoordinator-Example/Scenes/Login/LoginViewModelImpl.swift index 14360a1..4fbce9b 100644 --- a/XCoordinator-Example/Scenes/Login/LoginViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/Login/LoginViewModelImpl.swift @@ -19,16 +19,16 @@ class LoginViewModelImpl: LoginViewModel, LoginViewModelInput, LoginViewModelOut // MARK: Actions private lazy var loginAction = CocoaAction { [unowned self] in - self.router.rx.trigger(.home(nil)) + self.router.rxTrigger(.home(nil)) } // MARK: Stored properties - private let router: UnownedRouter + private unowned let router: any Router // MARK: Initialization - init(router: UnownedRouter) { + init(router: any Router) { self.router = router } } diff --git a/XCoordinator-Example/Scenes/News/NewsViewModelImpl.swift b/XCoordinator-Example/Scenes/News/NewsViewModelImpl.swift index d329ab8..7899317 100644 --- a/XCoordinator-Example/Scenes/News/NewsViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/News/NewsViewModelImpl.swift @@ -19,7 +19,7 @@ class NewsViewModelImpl: NewsViewModel, NewsViewModelInput, NewsViewModelOutput // MARK: Actions lazy var newsSelectedAction = Action { [unowned self] news in - self.router.rx.trigger(.newsDetail(news)) + self.router.rxTrigger(.newsDetail(news)) } // MARK: Outputs @@ -32,11 +32,11 @@ class NewsViewModelImpl: NewsViewModel, NewsViewModelInput, NewsViewModelOutput // MARK: Stored properties private let newsService: NewsService - private let router: UnownedRouter + private unowned let router: any Router // MARK: Initialization - init(newsService: NewsService, router: UnownedRouter) { + init(newsService: NewsService, router: any Router) { self.newsService = newsService self.newsObservable = .just(newsService.mostRecentNews()) self.router = router diff --git a/XCoordinator-Example/Scenes/User/UserViewModelImpl.swift b/XCoordinator-Example/Scenes/User/UserViewModelImpl.swift index ea1b96b..30b3bf6 100644 --- a/XCoordinator-Example/Scenes/User/UserViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/User/UserViewModelImpl.swift @@ -20,11 +20,11 @@ class UserViewModelImpl: UserViewModel, UserViewModelInput, UserViewModelOutput // MARK: Actions private lazy var alertAction = CocoaAction { [unowned self] in - self.router.rx.trigger(.alert(title: "Hey", message: "You are awesome!")) + self.router.rxTrigger(.alert(title: "Hey", message: "You are awesome!")) } private lazy var closeAction = CocoaAction { [unowned self] in - self.router.rx.trigger(.users) + self.router.rxTrigger(.users) } // MARK: Outputs @@ -33,11 +33,11 @@ class UserViewModelImpl: UserViewModel, UserViewModelInput, UserViewModelOutput // MARK: Stored properties - private let router: UnownedRouter + private unowned let router: any Router // MARK: Initialization - init(router: UnownedRouter, username: String) { + init(router: any Router, username: String) { self.router = router self.username = .just(username) } diff --git a/XCoordinator-Example/Scenes/UserList/UsersViewModelImpl.swift b/XCoordinator-Example/Scenes/UserList/UsersViewModelImpl.swift index c787695..29e3799 100644 --- a/XCoordinator-Example/Scenes/UserList/UsersViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/UserList/UsersViewModelImpl.swift @@ -19,7 +19,7 @@ class UsersViewModelImpl: UsersViewModel, UsersViewModelInput, UsersViewModelOut // MARK: Actions private lazy var showUserAction = Action { [unowned self] user in - self.router.rx.trigger(.user(user.name)) + self.router.rxTrigger(.user(user.name)) } // MARK: Outputs @@ -29,11 +29,11 @@ class UsersViewModelImpl: UsersViewModel, UsersViewModelInput, UsersViewModelOut // MARK: Stored properties private let userService: UserService - private let router: UnownedRouter + private unowned let router: any Router // MARK: Initialization - init(userService: UserService, router: UnownedRouter) { + init(userService: UserService, router: any Router) { self.userService = userService self.router = router } From 2e2d44f04bb3ac53d97c130a1b395d9adb4051ce Mon Sep 17 00:00:00 2001 From: Paul Kraft Date: Mon, 1 May 2023 12:57:24 +0200 Subject: [PATCH 2/5] Make it work with any Router --- .../xcshareddata/swiftpm/Package.resolved | 2 +- .../Coordinators/HomePageCoordinator.swift | 16 +++++++------- .../Coordinators/HomeSplitCoordinator.swift | 22 +++++++++++++------ .../Coordinators/HomeTabCoordinator.swift | 12 +++++----- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index f0966d2..7f37427 100644 --- a/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -24,7 +24,7 @@ "location" : "https://github.com/quickbirdstudios/XCoordinator.git", "state" : { "branch" : "feature/3.0.0", - "revision" : "e5ab085bbd758cb6edaa265b62bd2a8ea318c093" + "revision" : "3e1d1ab83a08ec0416f8715e3f1eae8ed233bad1" } } ], diff --git a/XCoordinator-Example/Coordinators/HomePageCoordinator.swift b/XCoordinator-Example/Coordinators/HomePageCoordinator.swift index 5144c0f..927e205 100644 --- a/XCoordinator-Example/Coordinators/HomePageCoordinator.swift +++ b/XCoordinator-Example/Coordinators/HomePageCoordinator.swift @@ -12,13 +12,13 @@ class HomePageCoordinator: PageCoordinator { // MARK: Stored properties - private let newsRouter: any Presentable - private let userListRouter: any Presentable + private let newsRouter: any Router + private let userListRouter: any Router // MARK: Initialization - init(newsRouter: any Presentable = NewsCoordinator(), - userListRouter: any Presentable = UserListCoordinator()) { + init(newsRouter: any Router = NewsCoordinator(), + userListRouter: any Router = UserListCoordinator()) { self.newsRouter = newsRouter self.userListRouter = userListRouter @@ -26,8 +26,8 @@ class HomePageCoordinator: PageCoordinator { rootViewController: .init(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil), - pages: [userListRouter, newsRouter], loop: false, - set: userListRouter, direction: .forward + pages: [userListRouter.asPresentable, newsRouter.asPresentable], loop: false, + set: userListRouter.asPresentable, direction: .forward ) } @@ -36,9 +36,9 @@ class HomePageCoordinator: PageCoordinator { override func prepareTransition(for route: HomeRoute) -> PageTransition { switch route { case .news: - return .set(newsRouter, direction: .forward) + return .set(newsRouter.asPresentable, direction: .forward) case .userList: - return .set(userListRouter, direction: .reverse) + return .set(userListRouter.asPresentable, direction: .reverse) } } diff --git a/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift b/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift index 4c97009..8c4e4eb 100644 --- a/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift +++ b/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift @@ -12,17 +12,17 @@ class HomeSplitCoordinator: SplitCoordinator { // MARK: Stored properties - private let newsRouter: any Presentable - private let userListRouter: any Presentable + private let newsRouter: any Router + private let userListRouter: any Router // MARK: Initialization - init(newsRouter: any Presentable = NewsCoordinator(), - userListRouter: any Presentable = UserListCoordinator()) { + init(newsRouter: any Router = NewsCoordinator(), + userListRouter: any Router = UserListCoordinator()) { self.newsRouter = newsRouter self.userListRouter = userListRouter - super.init(primary: userListRouter, secondary: newsRouter) + super.init(primary: userListRouter.asPresentable, secondary: newsRouter.asPresentable) } // MARK: Overrides @@ -30,10 +30,18 @@ class HomeSplitCoordinator: SplitCoordinator { override func prepareTransition(for route: HomeRoute) -> SplitTransition { switch route { case .news: - return .showDetail(newsRouter) + return .showDetail(newsRouter.asPresentable) case .userList: - return .show(userListRouter) + return .show(userListRouter.asPresentable) } } } + +extension Router { + + var asPresentable: any Presentable { + self + } + +} diff --git a/XCoordinator-Example/Coordinators/HomeTabCoordinator.swift b/XCoordinator-Example/Coordinators/HomeTabCoordinator.swift index ccdf199..bb3d466 100644 --- a/XCoordinator-Example/Coordinators/HomeTabCoordinator.swift +++ b/XCoordinator-Example/Coordinators/HomeTabCoordinator.swift @@ -18,8 +18,8 @@ class HomeTabCoordinator: TabBarCoordinator { // MARK: Stored properties - private let newsRouter: any Presentable - private let userListRouter: any Presentable + private let newsRouter: any Router + private let userListRouter: any Router // MARK: Initialization @@ -33,11 +33,11 @@ class HomeTabCoordinator: TabBarCoordinator { self.init(newsRouter: newsCoordinator, userListRouter: userListCoordinator) } - init(newsRouter: any Presentable, userListRouter: any Presentable) { + init(newsRouter: any Router, userListRouter: any Router) { self.newsRouter = newsRouter self.userListRouter = userListRouter - super.init(tabs: [newsRouter, userListRouter], select: userListRouter) + super.init(tabs: [newsRouter.asPresentable, userListRouter.asPresentable], select: userListRouter.asPresentable) } // MARK: Overrides @@ -45,9 +45,9 @@ class HomeTabCoordinator: TabBarCoordinator { override func prepareTransition(for route: HomeRoute) -> TabBarTransition { switch route { case .news: - return .select(newsRouter) + return .select(newsRouter.asPresentable) case .userList: - return .select(userListRouter) + return .select(userListRouter.asPresentable) } } From 5b4fab9e1dd4d039840223b94ca31185c8c2a0e6 Mon Sep 17 00:00:00 2001 From: Paul Kraft Date: Mon, 1 May 2023 13:03:42 +0200 Subject: [PATCH 3/5] Fix HomeRouter situation --- .../Coordinators/AppCoordinator.swift | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/XCoordinator-Example/Coordinators/AppCoordinator.swift b/XCoordinator-Example/Coordinators/AppCoordinator.swift index 33d835e..537d671 100644 --- a/XCoordinator-Example/Coordinators/AppCoordinator.swift +++ b/XCoordinator-Example/Coordinators/AppCoordinator.swift @@ -11,7 +11,7 @@ import XCoordinator enum AppRoute: Route { case login - case home((any Presentable)?) + case home((any Router)?) case newsDetail(News) } @@ -34,7 +34,7 @@ class AppCoordinator: NavigationCoordinator { return .push(viewController) case let .home(router): if let router { - return .presentFullScreen(router, animation: .fade) + return .presentFullScreen(router.asPresentable, animation: .fade) } let alert = UIAlertController( title: "How would you like to login?", @@ -57,12 +57,16 @@ class AppCoordinator: NavigationCoordinator { ) alert.addAction( .init(title: "Random", style: .default) { [unowned self] _ in - let routers: [() -> any Presentable] = [ - { HomeTabCoordinator() }, - { HomeSplitCoordinator() }, - { HomeTabCoordinator() } - ] - let router = routers.randomElement().map { $0() } + let router: any Router = { + switch Int.random(in: 0..<3) { + case 0: + return HomeTabCoordinator() + case 1: + return HomeSplitCoordinator() + default: + return HomeTabCoordinator() + } + }() self.trigger(.home(router)) } ) From 050a9c0b428fab5dfe6253fff96c3604636d5591 Mon Sep 17 00:00:00 2001 From: Paul Kraft Date: Mon, 1 May 2023 13:09:31 +0200 Subject: [PATCH 4/5] Use asPresentable extension --- .../xcshareddata/swiftpm/Package.resolved | 2 +- .../Coordinators/HomeSplitCoordinator.swift | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 7f37427..8197098 100644 --- a/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -24,7 +24,7 @@ "location" : "https://github.com/quickbirdstudios/XCoordinator.git", "state" : { "branch" : "feature/3.0.0", - "revision" : "3e1d1ab83a08ec0416f8715e3f1eae8ed233bad1" + "revision" : "2f68db87dffcc69d4ad3bdca5d0ca7c1f21ca78f" } } ], diff --git a/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift b/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift index 8c4e4eb..9256f6a 100644 --- a/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift +++ b/XCoordinator-Example/Coordinators/HomeSplitCoordinator.swift @@ -37,11 +37,3 @@ class HomeSplitCoordinator: SplitCoordinator { } } - -extension Router { - - var asPresentable: any Presentable { - self - } - -} From 14d2d68e8ef0d112c5476bc221c57fd3e07e5c8e Mon Sep 17 00:00:00 2001 From: Paul Kraft Date: Fri, 5 May 2023 12:10:59 +0200 Subject: [PATCH 5/5] Update to newest version --- .../xcshareddata/swiftpm/Package.resolved | 2 +- XCoordinator-Example/Scenes/About/AboutViewModelImpl.swift | 2 +- XCoordinator-Example/Scenes/Home/HomeViewModelImpl.swift | 6 +++--- XCoordinator-Example/Scenes/Login/LoginViewModelImpl.swift | 2 +- XCoordinator-Example/Scenes/News/NewsViewModelImpl.swift | 2 +- XCoordinator-Example/Scenes/User/UserViewModelImpl.swift | 4 ++-- .../Scenes/UserList/UsersViewModelImpl.swift | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 8197098..f178ff5 100644 --- a/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XCoordinator-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -24,7 +24,7 @@ "location" : "https://github.com/quickbirdstudios/XCoordinator.git", "state" : { "branch" : "feature/3.0.0", - "revision" : "2f68db87dffcc69d4ad3bdca5d0ca7c1f21ca78f" + "revision" : "aef3a89868b4e12e6191f2d72282cb9415dbc6ea" } } ], diff --git a/XCoordinator-Example/Scenes/About/AboutViewModelImpl.swift b/XCoordinator-Example/Scenes/About/AboutViewModelImpl.swift index 94e49ef..1f72ebe 100644 --- a/XCoordinator-Example/Scenes/About/AboutViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/About/AboutViewModelImpl.swift @@ -20,7 +20,7 @@ class AboutViewModelImpl: AboutViewModel, AboutViewModelInput, AboutViewModelOut // MARK: Actions private lazy var openWebsiteAction = CocoaAction { [unowned self] in - self.router.rxTrigger(.website) + self.router.rx.trigger(.website) } // MARK: Outputs diff --git a/XCoordinator-Example/Scenes/Home/HomeViewModelImpl.swift b/XCoordinator-Example/Scenes/Home/HomeViewModelImpl.swift index 68f074f..9499d17 100644 --- a/XCoordinator-Example/Scenes/Home/HomeViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/Home/HomeViewModelImpl.swift @@ -22,15 +22,15 @@ class HomeViewModelImpl: HomeViewModel, HomeViewModelInput, HomeViewModelOutput // MARK: Actions private lazy var logoutAction = CocoaAction { [unowned self] in - self.router.rxTrigger(.logout) + self.router.rx.trigger(.logout) } private lazy var usersAction = CocoaAction { [unowned self] in - self.router.rxTrigger(.users) + self.router.rx.trigger(.users) } private lazy var aboutAction = CocoaAction { [unowned self] in - self.router.rxTrigger(.about) + self.router.rx.trigger(.about) } // MARK: Stored properties diff --git a/XCoordinator-Example/Scenes/Login/LoginViewModelImpl.swift b/XCoordinator-Example/Scenes/Login/LoginViewModelImpl.swift index 4fbce9b..d18f675 100644 --- a/XCoordinator-Example/Scenes/Login/LoginViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/Login/LoginViewModelImpl.swift @@ -19,7 +19,7 @@ class LoginViewModelImpl: LoginViewModel, LoginViewModelInput, LoginViewModelOut // MARK: Actions private lazy var loginAction = CocoaAction { [unowned self] in - self.router.rxTrigger(.home(nil)) + self.router.rx.trigger(.home(nil)) } // MARK: Stored properties diff --git a/XCoordinator-Example/Scenes/News/NewsViewModelImpl.swift b/XCoordinator-Example/Scenes/News/NewsViewModelImpl.swift index 7899317..7d2571c 100644 --- a/XCoordinator-Example/Scenes/News/NewsViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/News/NewsViewModelImpl.swift @@ -19,7 +19,7 @@ class NewsViewModelImpl: NewsViewModel, NewsViewModelInput, NewsViewModelOutput // MARK: Actions lazy var newsSelectedAction = Action { [unowned self] news in - self.router.rxTrigger(.newsDetail(news)) + self.router.rx.trigger(.newsDetail(news)) } // MARK: Outputs diff --git a/XCoordinator-Example/Scenes/User/UserViewModelImpl.swift b/XCoordinator-Example/Scenes/User/UserViewModelImpl.swift index 30b3bf6..88d1ed6 100644 --- a/XCoordinator-Example/Scenes/User/UserViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/User/UserViewModelImpl.swift @@ -20,11 +20,11 @@ class UserViewModelImpl: UserViewModel, UserViewModelInput, UserViewModelOutput // MARK: Actions private lazy var alertAction = CocoaAction { [unowned self] in - self.router.rxTrigger(.alert(title: "Hey", message: "You are awesome!")) + self.router.rx.trigger(.alert(title: "Hey", message: "You are awesome!")) } private lazy var closeAction = CocoaAction { [unowned self] in - self.router.rxTrigger(.users) + self.router.rx.trigger(.users) } // MARK: Outputs diff --git a/XCoordinator-Example/Scenes/UserList/UsersViewModelImpl.swift b/XCoordinator-Example/Scenes/UserList/UsersViewModelImpl.swift index 29e3799..4ad7d8e 100644 --- a/XCoordinator-Example/Scenes/UserList/UsersViewModelImpl.swift +++ b/XCoordinator-Example/Scenes/UserList/UsersViewModelImpl.swift @@ -19,7 +19,7 @@ class UsersViewModelImpl: UsersViewModel, UsersViewModelInput, UsersViewModelOut // MARK: Actions private lazy var showUserAction = Action { [unowned self] user in - self.router.rxTrigger(.user(user.name)) + self.router.rx.trigger(.user(user.name)) } // MARK: Outputs