aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--foray/Coordinators/Coordinator.swift11
-rw-r--r--foray/Coordinators/ForayCoordinator.swift9
-rw-r--r--foray/Scenes/ForayDetailViewController.swift3
-rw-r--r--foray/Scenes/ForayTableViewController.swift4
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?