aboutsummaryrefslogtreecommitdiff
path: root/foray/Coordinators
diff options
context:
space:
mode:
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)
}