Coordinator
open class Coordinator<T> : NSObject, Coordinating where T : UIViewController, T : Coordinated
This is the base Coordinator class, for cases that you do not need manage any child Coordinator. Intended to be used as a wrapper to your UIViewController and manage its data fetching and other concerns, keeping your UIViewController as simple as possible.
T must be a UIViewController and at the same time conform to Coordinated
-
The rootViewController from this Coordinator. This is the UIViewController passed throught the generic parameter, it is never changed during the Coordinator’s lifecycle.
Declaration
Swift
public var rootViewController: T -
Declaration
Swift
open lazy var identifier: String { get set } -
Declaration
Swift
open weak var parentCoordinator: Coordinating? -
Declaration
Swift
private(set) public var isStarted: Bool -
This is the beginning of the Coordinator Lifecycle. It will set the rootViewController as a instance of T and assign itself as the Coordinator of the same UIViewController.
If you need to override this, because your T needs arguments to be initialized or other reason, do not forget to assign this Coordinator rootViewController and the UIViewController Coordinator to this instance. This is essentially the required connection to make the rest work.
Declaration
Swift
public override init()
-
Use this method to start anything that might be necessary before its rootViewController is presented.
Note: if you override this method, you must call
superand pass thecompletionclosure.Declaration
Swift
open func start(with completion: @escaping () -> Void = {})Parameters
completionAn optional
Callbackexecuted at the end. -
Tells the Coordinator that it is done, releases the rootViewController to be cleared out of memory.
If you override this method, you must call
superand pass thecompletionclosure.Declaration
Swift
open func stop(with completion: @escaping () -> Void = {})Parameters
completionClosure to execute at the end.
-
Activates the Coordinator.
By default this does nothing, but always call super.activte() in case you override this to make sure its compatible with future implementations.
Declaration
Swift
open func activate() -
Declaration
Swift
public func getRootViewController() -> UIViewController
-
Emits an Event that will bubble up the UIResponder chain until reaches the first Coordinator, where it will continue to bubble up
Declaration
Swift
public func emitEvent(_ event: CoordinateEvents)Parameters
eventThe event to emit
-
Intercepts events and react to them. Return true to stop the event propagation, return false to continue event propagation
If you override this method, you can cast the event parameter to the desired enum you wish to compare.
Declaration
Swift
open func interceptEvent(_ event: CoordinateEvents) -> BoolParameters
eventThe event to intercept
View on GitHub
Install in Dash
Coordinator Class Reference