ContainerFlowStack

public class ContainerFlowStack

This is the class that will be responsible to create and handle the stack of the view controllers that we will register to be used during our navigation using our flow manager class.

  • Initializer for generate ContainerFlowStack so you can create an instance and register all the dependencies that you will use in your flow manager

    Declaration

    Swift

    @discardableResult
    public init()
  • Helper initializer that let you setup, register your depencies direct inside the constructor, as it’s a closure that after initialize the instance return so you can use to register your dependencies

    Usage Example:

    let navigationStack = ContainerFlowStack { flowStack in
        flowStack.registerModule(for: AutomaticallyFirstViewController.self, resolve: { () -> AutomaticallyFirstViewController in
           return AutomaticallyFirstViewController()
        })
    
        flowStack.registerModule(for: AutomaticallySecondViewController.self, resolve: { () -> AutomaticallySecondViewController in
           return AutomaticallySecondViewController()
        })
    }
    

    Declaration

    Swift

    @discardableResult
    public convenience init(for instances: (ContainerFlowStack) -> ())

    Parameters

    instance

    Closure that has ContainerFlowStack instance.

  • This is the registration method, it’s used for you register the View Controllers that you will use in your flow manager, the order that you declare will be used if you use the automatic navigation method.

    Usage Example:

       ContainerFlowStack().registerModule(for: DeeplinkInitialViewController.self) { () -> DeeplinkInitialViewController in
           return DeeplinkInitialViewController()
       }
    

    Declaration

    Swift

    @discardableResult
    public func registerModule<T: UIViewController>(for type: T.Type, resolve: @escaping () -> T?) -> FlowElementContainer<UIViewController>

    Parameters

    type

    The Type of your View Controller that you want to register.

    resolve

    Closure that will be called to get the instance that you registered, is the same as your type.

  • This is the registration method, it’s used for you register the View Controllers that you will use in your flow manager, the order that you declare will be used if you use the automatic navigation method.

    Usage Example:

       ContainerFlowStack().registerModule(for: DeeplinkInitialViewController.self, customIdentifier: "MyCustomView") { () -> DeeplinkInitialViewController in
           return DeeplinkInitialViewController()
       }
    

    Declaration

    Swift

    @discardableResult
    public func registerModule<T: UIViewController>(for type: T.Type, customIdentifier: String, resolve: @escaping () -> T?) -> FlowElementContainer<UIViewController>

    Parameters

    type

    The Type of your View Controller that you want to register.

    customIdentifier

    String that is custom identifier to identify particular view

    resolve

    Closure that will be called to get the instance that you registered, is the same as your type.

  • Helper method that will return all modules that you have registered inside this container

    Declaration

    Swift

    public func getModulesList() -> [FlowElementContainer<UIViewController>]

    Return Value

    Array of type FlowElementContainer.

  • Helper that for check if you have this View controller instance, it’s intended to use for you check if that instance already was instantiated or not, if you never called this instance will return nil.

    Usage Example:

       ContainerFlowStack().registerModule(for: DeeplinkInitialViewController.self) { () -> DeeplinkInitialViewController in
           return DeeplinkInitialViewController()
       }
    

    Declaration

    Swift

    public func getModuleIfHasInstance<T>(for type: T.Type) -> T? where T : UIViewController

    Parameters

    type

    UIViewController type that you want to check.

    Return Value

    The object instance reference.

  • This is the registration method for your view controller that you will receive some parameter when try to resolve, try to navigate using flow manager, you will be able to declare what you will expect as parameter, here you need to declare the type of the parameters that you will receive, and it’s mandatory if you have one or more they be in the same order as when you send the parameter.

    Note

    It has @discardableResult because you can use other helper methods just after calling this method as we always return Container Flow Stack instance.

    Usage Example:

        containerStack.registerModuleWithParameter(for: ParameterInitialViewController.self) { (arguments: (String, Double, String, Int)) -> ParameterInitialViewController? in
    
           let (first, second, third, fourth) = arguments
    
           let initialViewController = ParameterInitialViewController()
           initialViewController.setParameters(first: first, second, third, fourth)
    
           return initialViewController
        }
    
        // Or if you have a custom identifier
        containerStack.registerModuleWithParameter(for: ParameterInitialViewController.self, customIdentifier: "MyCustomViewToLoad") { (arguments: (String, Double, String, Int)) -> ParameterInitialViewController? in
    
               let (first, second, third, fourth) = arguments
    
               let initialViewController = ParameterInitialViewController()
               initialViewController.setParameters(first: first, second, third, fourth)
    
               return initialViewController
            }
    

    Important

    If you want to use more than one parameter it’s important to use tuple, as how generic works in order to identify you need to have a type of the thing so generics will understand about, this is why when we have multiples parameter we type as tuple.

    Declaration

    Swift

    @discardableResult
    public func registerModuleWithParameter<T: UIViewController, Resolver>(for type: T.Type, customIdentifier: String? = nil, resolve: @escaping ((Resolver)) -> T?) -> FlowElementContainer<UIViewController>

    Parameters

    type

    The View Controller type that you want to register.

    customIdentifier

    optional - String that is custom identifier to identify particular view

    resolve

    Closure with the declaration of the type(s) that you will expect as parameter.

    Return Value

    FlowElementContainer container.