From 17602e7017714452358808d8c9d4c362f7356bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Vacic=CC=81?= Date: Thu, 7 Mar 2024 09:23:04 +0100 Subject: [PATCH] Removed all the async markers. They don't see needed at all, since this is UI display work anyway. --- Coordinator/Coordinating.swift | 10 +++++----- Coordinator/Coordinator.swift | 16 ++++++++-------- Coordinator/NavigationCoordinator.swift | 22 +++++++++------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Coordinator/Coordinating.swift b/Coordinator/Coordinating.swift index 52da227..eed5ec8 100644 --- a/Coordinator/Coordinating.swift +++ b/Coordinator/Coordinating.swift @@ -30,25 +30,25 @@ public protocol Coordinating: AnyObject { /// Tells the coordinator to start, which means at the end of this method it should /// display some UIViewController. - func start() async + func start() /// Tells the coordinator to stop, which means it should clear out any internal stuff /// it possibly tracks. /// I.e. list of shown `UIViewController`s. - func stop() async + func stop() /// Essentially, this means that Coordinator requests from its parent to stop it. /// /// Useful in cases where a particular Coordinator instance know that at particular /// moment none of its UIVCs will be visible or useful anymore. /// This is a chance for parentCoordinator to nicely transitions to some other Coordinator. - func coordinatorDidFinish(_ coordinator: Coordinating) async + func coordinatorDidFinish(_ coordinator: Coordinating) /// Adds the supplied coordinator into its `childCoordinators` dictionary and calls its `start` method - func startChild(coordinator: Coordinating) async + func startChild(coordinator: Coordinating) /// Calls `stop` on the supplied coordinator and removes it from its `childCoordinators` dictionary - func stopChild(coordinator: Coordinating) async + func stopChild(coordinator: Coordinating) /// Activate Coordinator which was used before. /// diff --git a/Coordinator/Coordinator.swift b/Coordinator/Coordinator.swift index 47425d1..529c70c 100644 --- a/Coordinator/Coordinator.swift +++ b/Coordinator/Coordinator.swift @@ -92,7 +92,7 @@ open class Coordinator: UIResponder, Coordinating { /// - Parameter completion: An optional `Callback` executed at the end. /// /// Note: if you override this method, you must call `super` and pass the `completion` closure. - open func start() async { + open func start() { rootViewController.parentCoordinator = self isStarted = true } @@ -105,7 +105,7 @@ open class Coordinator: UIResponder, Coordinating { /// - Parameter completion: Closure to execute at the end. /// /// Note: if you override this method, you must call `super` and pass the `completion` closure. - open func stop() async { + open func stop() { rootViewController.parentCoordinator = nil } @@ -114,8 +114,8 @@ open class Coordinator: UIResponder, Coordinating { /// (See also comments for this method in the Coordinating protocol) /// /// Note: if you override this method, you should call `super` and pass the `completion` closure. - open func coordinatorDidFinish(_ coordinator: Coordinating) async { - await stopChild(coordinator: coordinator) + open func coordinatorDidFinish(_ coordinator: Coordinating) { + stopChild(coordinator: coordinator) } /// Coordinator can be in memory, but it‘s not currently displaying anything. @@ -155,10 +155,10 @@ open class Coordinator: UIResponder, Coordinating { - Parameter coordinator: The coordinator implementation to start. - Parameter completion: An optional `Callback` passed to the coordinator's `start()` method. */ - public func startChild(coordinator: Coordinating) async { + public func startChild(coordinator: Coordinating) { childCoordinators[coordinator.identifier] = coordinator coordinator.parent = self - await coordinator.start() + coordinator.start() } @@ -168,10 +168,10 @@ open class Coordinator: UIResponder, Coordinating { - Parameter coordinator: The coordinator implementation to stop. - Parameter completion: An optional `Callback` passed to the coordinator's `stop()` method. */ - public func stopChild(coordinator: Coordinating) async { + public func stopChild(coordinator: Coordinating) { coordinator.parent = nil self.childCoordinators.removeValue(forKey: coordinator.identifier) - await coordinator.stop() + coordinator.stop() } diff --git a/Coordinator/NavigationCoordinator.swift b/Coordinator/NavigationCoordinator.swift index ebcd7d2..2381666 100644 --- a/Coordinator/NavigationCoordinator.swift +++ b/Coordinator/NavigationCoordinator.swift @@ -124,14 +124,14 @@ open class NavigationCoordinator: Coordinator, UINavigat // MARK:- Coordinator lifecycle - open override func start() async { + open override func start() { // assign itself as UINavigationControllerDelegate rootViewController.delegate = self // must call this - await super.start() + super.start() } - open override func stop() async { + open override func stop() { // relinquish being delegate for UINC rootViewController.delegate = nil @@ -145,14 +145,14 @@ open class NavigationCoordinator: Coordinator, UINavigat viewControllers.removeAll() // must call this - await super.stop() + super.stop() } - override open func coordinatorDidFinish(_ coordinator: Coordinating) async { + override open func coordinatorDidFinish(_ coordinator: Coordinating) { // some child Coordinator reports that it's done // (pop-ed back from, most likely) - await super.coordinatorDidFinish(coordinator) + super.coordinatorDidFinish(coordinator) // figure out which Coordinator should now take ownershop of root NC guard let topVC = self.rootViewController.topViewController else { @@ -178,7 +178,7 @@ open class NavigationCoordinator: Coordinator, UINavigat } // if nothing found, then this Coordinator is also done, along with its child - await self.parent?.coordinatorDidFinish(self) + self.parent?.coordinatorDidFinish(self) } open override func activate() { @@ -206,9 +206,7 @@ private extension NavigationCoordinator { // Check: is there any controller left shown in this Coordinator? if viewControllers.count == 0 { // there isn't thus inform the parent Coordinator that this child Coordinator is done. - Task { - await parent?.coordinatorDidFinish(self) - } + parent?.coordinatorDidFinish(self) return } @@ -225,9 +223,7 @@ private extension NavigationCoordinator { // | Note: using firstIndex(of:) and not .last nicely handles if you programatically pop more than one UIVC. guard let index = viewControllers.firstIndex(of: viewController) else { // it's not, it means UINC moved to some other Coordinator domain and thus bail out from here - Task { - await parent?.coordinatorDidFinish(self) - } + parent?.coordinatorDidFinish(self) return }