ContainerAdapter

public protocol ContainerAdapter

Provides universal properties and methods of the ContainerViewController instance.

ContainerViewControllers are different from the simple ones in that they can contain child view controllers which are also containers or simple ones. These view controllers are available out of the box: UINavigationController, UITabBarController and so on, but there can be custom ones created as well.

All the container view controller have the following properties:

  1. The list of all the view controllers that they contain.
  2. One or more view controllers are currently visible.
  3. They can make one of these view controllers visible.
  4. They can replace all of their contained view controllers.

Properties to implement

Methods to implement

  • Each container view controller adapter should implement this method for the Router to know how to make its particular child view controller visible.

    NB: completion block must be called.

    Declaration

    Swift

    func makeVisible(_ viewController: UIViewController, animated: Bool, completion: @escaping (RoutingResult) -> Void)

    Parameters

    viewController

    The UIViewController to make active (visible).

    animated

    If ContainerViewController is able to do so - make container active animated or not.

  • Each container view controller adapter should implement this method for the Router to know how to replace all the view controllers in this particular container view controller.

    NB: completion block must be called.

    Declaration

    Swift

    func setContainedViewControllers(_ containedViewControllers: [UIViewController], animated: Bool, completion: @escaping (RoutingResult) -> Void)

    Parameters

    containedViewControllers

    A UIViewController instances to replace.

    animated

    If ContainerViewController is able to do so - replace contained view controllers animated or not.

Helper methods

  • contains(_:) Extension method

    Checks if the provided view controller is present amongst the contained view controllers.

    Declaration

    Swift

    func contains(_ viewController: UIViewController) -> Bool

    Parameters

    viewController

    UIViewController instance

    Return Value

    true if present, false otherwise.

  • isVisible(_:) Extension method

    Checks if the provided view controller is present amongst the visible view controllers.

    Declaration

    Swift

    func isVisible(_ viewController: UIViewController) -> Bool

    Parameters

    viewController

    UIViewController instance

    Return Value

    true if present, false otherwise.