Router
public protocol Router : Presentable
The Router protocol is used to abstract the transition-type specific characteristics of a Coordinator.
A Router can trigger routes, which lead to transitions being executed. In constrast to the Coordinator protocol,
the router does not specify a TransitionType and can therefore be used in the form of a
StrongRouter
, UnownedRouter
or WeakRouter
to reduce a coordinator’s capabilities to
the triggering of routes.
This may especially be useful in viewModels when using them in different contexts.
-
RouteType defines which routes can be triggered in a certain Router implementation.
Declaration
Swift
associatedtype RouteType : Route
-
Triggers routes and returns context in completion-handler.
Useful for deep linking. It is encouraged to use
trigger
instead, if the context is not needed.Declaration
Swift
func contextTrigger(_ route: RouteType, with options: TransitionOptions, completion: ContextPresentationHandler?)
Parameters
route
The route to be triggered.
options
Transition options configuring the execution of transitions, e.g. whether it should be animated.
completion
If present, this completion handler is executed once the transition is completed (including animations). If the context is not needed, use
trigger
instead.
-
trigger(_:with:)
Extension methodTriggers the specified route without the need of specifying a completion handler.
Declaration
Swift
public func trigger(_ route: RouteType, with options: TransitionOptions)
Parameters
route
The route to be triggered.
options
Transition options for performing the transition, e.g. whether it should be animated.
-
trigger(_:completion:)
Extension methodTriggers the specified route with default transition options enabling the animation of the transition.
Declaration
Swift
public func trigger(_ route: RouteType, completion: PresentationHandler? = nil)
Parameters
route
The route to be triggered.
completion
If present, this completion handler is executed once the transition is completed (including animations).
-
trigger(_:with:completion:)
Extension methodTriggers the specified route by performing a transition.
Declaration
Swift
public func trigger(_ route: RouteType, with options: TransitionOptions, completion: PresentationHandler?)
Parameters
route
The route to be triggered.
options
Transition options for performing the transition, e.g. whether it should be animated.
completion
If present, this completion handler is executed once the transition is completed (including animations).
-
strongRouter
Extension methodCreates a StrongRouter object from the given router to abstract from concrete implementations while maintaining information necessary to fulfill the Router protocol. The original router will be held strongly.
Declaration
Swift
public var strongRouter: StrongRouter<RouteType> { get }
-
router(for:)
Extension methodReturns a router for the specified route, if possible.
Declaration
Swift
public func router<R>(for route: R) -> StrongRouter<R>? where R : Route
Parameters
route
The route type to return a router for.
Return Value
It returns the router’s strongRouter, if it is compatible with the given route type, otherwise
nil
.