aboutsummaryrefslogtreecommitdiff
path: root/foray/Coordinators
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-07-17 01:51:31 +1000
committerNicholas Tay <nick@windblume.net>2022-07-17 01:51:31 +1000
commit358f540104aa38b3911f913a0bca047921210205 (patch)
tree8bd3bf1be7186bd9b8532a44dbd1dc17ccd38fa5 /foray/Coordinators
parente963970c62bd9fb8007694143fb90ecaea198da2 (diff)
downloadforayios-358f540104aa38b3911f913a0bca047921210205.tar.gz
forayios-358f540104aa38b3911f913a0bca047921210205.tar.bz2
forayios-358f540104aa38b3911f913a0bca047921210205.zip
Try out moving coordinator 'coordinated' VC thing
Diffstat (limited to '')
-rw-r--r--foray/Coordinators/Coordinator.swift11
-rw-r--r--foray/Coordinators/ForayCoordinator.swift9
2 files changed, 11 insertions, 9 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)
}