diff options
author | Nicholas Tay <nick@windblume.net> | 2022-07-17 01:51:31 +1000 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2022-07-17 01:51:31 +1000 |
commit | 358f540104aa38b3911f913a0bca047921210205 (patch) | |
tree | 8bd3bf1be7186bd9b8532a44dbd1dc17ccd38fa5 /foray | |
parent | e963970c62bd9fb8007694143fb90ecaea198da2 (diff) | |
download | forayios-358f540104aa38b3911f913a0bca047921210205.tar.gz forayios-358f540104aa38b3911f913a0bca047921210205.tar.bz2 forayios-358f540104aa38b3911f913a0bca047921210205.zip |
Try out moving coordinator 'coordinated' VC thing
Diffstat (limited to 'foray')
-rw-r--r-- | foray/Coordinators/Coordinator.swift | 11 | ||||
-rw-r--r-- | foray/Coordinators/ForayCoordinator.swift | 9 | ||||
-rw-r--r-- | foray/Scenes/ForayDetailViewController.swift | 3 | ||||
-rw-r--r-- | foray/Scenes/ForayTableViewController.swift | 4 |
4 files changed, 16 insertions, 11 deletions
diff --git a/foray/Coordinators/Coordinator.swift b/foray/Coordinators/Coordinator.swift index db97a1d..6858576 100644 --- a/foray/Coordinators/Coordinator.swift +++ b/foray/Coordinators/Coordinator.swift @@ -17,3 +17,14 @@ protocol Coordinator { func start() } +protocol Coordinated: UIViewController { + associatedtype CoordinatorType: Coordinator + var coordinator: CoordinatorType? { get set } +} + +extension Coordinator { + func push<T: Coordinated>(vc: T, animated: Bool = true) { + vc.coordinator = self as? T.CoordinatorType + navigationController.pushViewController(vc, animated: animated) + } +} diff --git a/foray/Coordinators/ForayCoordinator.swift b/foray/Coordinators/ForayCoordinator.swift index bb0c407..874f486 100644 --- a/foray/Coordinators/ForayCoordinator.swift +++ b/foray/Coordinators/ForayCoordinator.swift @@ -8,10 +8,6 @@ import Foundation import UIKit -protocol ForayCoordinated: UIViewController { - var coordinator: ForayCoordinator? { get set } -} - class ForayCoordinator: Coordinator { var childCoordinators = [Coordinator]() var navigationController: UINavigationController @@ -22,11 +18,6 @@ class ForayCoordinator: Coordinator { self.loadingOverlay = ForayLoadingOverlay(viewController: navigationController) } - private func push(vc: ForayCoordinated, animated: Bool = true) { - vc.coordinator = self - navigationController.pushViewController(vc, animated: animated) - } - func start() { push(vc: ForayTableViewController(), animated: false) } diff --git a/foray/Scenes/ForayDetailViewController.swift b/foray/Scenes/ForayDetailViewController.swift index 85b2929..1e2f9ca 100644 --- a/foray/Scenes/ForayDetailViewController.swift +++ b/foray/Scenes/ForayDetailViewController.swift @@ -7,9 +7,10 @@ import UIKit -class ForayDetailViewController: UIViewController, HasCustomView, ForayCoordinated { +class ForayDetailViewController: UIViewController, HasCustomView, Coordinated { typealias CustomView = ForayDetailView + typealias CoordinatorType = ForayCoordinator var coordinator: ForayCoordinator? diff --git a/foray/Scenes/ForayTableViewController.swift b/foray/Scenes/ForayTableViewController.swift index 72d3569..13b9dea 100644 --- a/foray/Scenes/ForayTableViewController.swift +++ b/foray/Scenes/ForayTableViewController.swift @@ -12,7 +12,9 @@ struct YearSection { var items: [PenguinItemViewModel] } -class ForayTableViewController: UITableViewController, ForayCoordinated { +class ForayTableViewController: UITableViewController, Coordinated { + + typealias CoordinatorType = ForayCoordinator let presenter: PenguinItemPresenter = PenguinItemPresenter() var coordinator: ForayCoordinator? |