ContainerCoordinator

open class ContainerCoordinator<T> : Coordinator<T>, HasChildren where T : UIViewController, T : Coordinated

The simplest Coordinator that can have other children Coordinators.

This does everything that Coordinator does plus managing the hierarchy and navigation flow, i.e. how the children are presented and where in the navigation flow. The idea is that you can use it as a switch between any kind of Coordinator.

  • Returns a cached children Coordinator if it exists

    Use this method to verify if the Coordinator you want to present is not already in use to avoid wasting resources or creating conflicts

    Declaration

    Swift

    public func getCached<C>(_ coordinatorType: C.Type) -> C?

    Parameters

    coordinatorType

    The Coordinator.Type from the Coordinator to be returned.

  • Analog to UIViewController’s show(_ vc: UIViewController, sender: Any?) method but for Coordinators.

    It makes sure that the Coordinator is properly initialized before presenting its rootViewController.

    Declaration

    Swift

    public func show(_ coordinator: Coordinating, sender: Any?)

    Parameters

    coordinator

    The Coordinator with the rootViewController to be presented.

    sender

    The sender.

  • Analog to UIViewController’s present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) method but for Coordinators.

    It makes sure that the Coordinator is properly initialized before presenting its rootViewController

    Declaration

    Swift

    public func present(_ coordinator: Coordinating, animated: Bool, completion: (() -> Void)?)

    Parameters

    coordinator

    The Coordinator with the rootViewController to be presented.

    animated

    Whether the transition should be animated or not.

    completion

    The block to execute after the presentation finishes. This block has no return value and takes no parameters. You may specify nil for this parameter.

  • Analog to UIViewController’s dismiss(animated flag: Bool, completion: (() -> Void)? = nil) method but for Coordinators.

    Declaration

    Swift

    public func dismiss(animated: Bool = true, completion: (() -> Void)? = nil)

    Parameters

    animated

    Whether the transition should be animated or not.

    completion

    The block to execute after the presentation finishes. This block has no return value and takes no parameters. You may specify nil for this parameter.

  • On a ContainerCoordinator, we can stack other Coordinators and change them with or without animation with this method.

    You can override this method and use custom Animations/Transitions.

    Declaration

    Swift

    open func root(_ coordinator: Coordinating, animated: Bool = false, completion: (() -> Void)? = nil)

    Parameters

    coordinator

    The Coordinator with the rootViewController to be presented.

    animated

    Whether the transition should be animated or not.

    completion

    The block to execute after the presentation finishes. This block has no return value and takes no parameters. You may specify nil for this parameter.