Skip to content

Commit

Permalink
Removed all the async markers.
Browse files Browse the repository at this point in the history
They don't see needed at all, since this is UI display work anyway.
  • Loading branch information
radianttap committed Mar 7, 2024
1 parent bed2e95 commit 17602e7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
10 changes: 5 additions & 5 deletions Coordinator/Coordinating.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
16 changes: 8 additions & 8 deletions Coordinator/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ open class Coordinator<T: UIViewController>: 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
}
Expand All @@ -105,7 +105,7 @@ open class Coordinator<T: UIViewController>: 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
}

Expand All @@ -114,8 +114,8 @@ open class Coordinator<T: UIViewController>: 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.
Expand Down Expand Up @@ -155,10 +155,10 @@ open class Coordinator<T: UIViewController>: 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()
}


Expand All @@ -168,10 +168,10 @@ open class Coordinator<T: UIViewController>: 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()
}


Expand Down
22 changes: 9 additions & 13 deletions Coordinator/NavigationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ open class NavigationCoordinator: Coordinator<UINavigationController>, 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

Expand All @@ -145,14 +145,14 @@ open class NavigationCoordinator: Coordinator<UINavigationController>, 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 {
Expand All @@ -178,7 +178,7 @@ open class NavigationCoordinator: Coordinator<UINavigationController>, 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() {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 17602e7

Please sign in to comment.