Koordinator is a simple and flexible implementation of the Coordinator pattern.
Overview
The Coordinator pattern can be used to solve the problem of orchestrating the iOS navigation.
This framework standardizes the navigation entities behaviour.
It also helps to manage the back button and the iOS 13 swipe down behaviour (isModalInPresentation),
so that a coordinator is automatically notified if its view controller gets dismiss/pop.
Example
- Let's say we want to push a view controller into a navigation stack, just need to subclass a
BaseCoordinatorand call thestartfunction:
let myNavigation: UINavigationController!
...
let coordinator = DemoCoordinator(presenter: myNavigation)
coordinator.start()
The a sub class of the BaseCoordinator could be simply defined as:
class DemoCoordinator: BaseCoordinator {
override func start() {
let someViewController = UIViewController()
show(someViewController)
}
}
- If, instead, we want to present modally a view controller, make sure the
Presenteris a simpleUIViewController:
let myNavigation: UINavigationController!
...
let coordinator = DemoCoordinator(presenter: myNavigation.visibleViewController)
coordinator.start()
Framework
The framework offers the following protocols and helper classes:
Koordinator: it's the navigation orchestrator, can create children coordinators, can make/show view controllers, it essentially manages their life cycle.
protocol Koordinator {
associatedtype Koordinator: Hashable
var children: Set<Koordinator> { get set }
var presenter: Presenter? { get set }
func start()
func start(child: Koordinator)
func show(_ viewController: UIViewController)
}
Presenter: it's the entity that shows the view controller.
If the presenter is a:UIViewController: the view controller is presentedUINavigationViewController: the view controller is pushedUITabBarController: the view controller is appended as a new tabUIWindow: the view controller becomes the root
protocol Presenter: class {
func show(_ viewController: UIViewController)
}
-
BaseCoordinator: Koordinator: plug and play implementation of the coordinator -
BaseViewController: UIViewController: helps to manage pop/dismiss callbacks to theBaseCoordinator

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

