Factory

public protocol Factory : AbstractFactory

The Factory protocol should be implemented by the instance that produces any types of the view controllers.

NB

Context represents a payload that you need to pass to your UIViewController and something that distinguishes it from others. It is not a View Model or some kind of Presenter. It is the missing piece of information. If your view controller requires a productID to display its content, and the productID is a UUID, then the type of Context is the UUID. The internal logic belongs to the view controller. Context answers the questions What to I need to present a ProductViewController and Am I already presenting a ProductViewController for this product.

Associated types

  • Type of UIViewController that Factory can build

    Declaration

    Swift

    associatedtype ViewController
  • Context to be passed into UIViewController

    Declaration

    Swift

    associatedtype Context

Methods to implement

  • Builds a UIViewController that will be integrated into the stack

    Throws

    The RoutingError if build did not succeed.

    Declaration

    Swift

    func build(with context: Context) throws -> ViewController

    Parameters

    context

    A Context instance that is provided to the Router.

    Return Value

    The built UIViewController instance.

Default implementation

  • prepare(with:) Extension method

    Default implementation does nothing

    Declaration

    Swift

    mutating func prepare(with context: Context) throws

Helper methods

Available where Context == Any?

  • build() Extension method

    Builds a Factory‘s view controller.

    Declaration

    Swift

    func build() throws -> ViewController
  • execute() Extension method

    Prepares the Factory and builds its UIViewController

    Declaration

    Swift

    func execute() throws -> ViewController

Available where Context == Void

  • build() Extension method

    Builds a Factory‘s view controller.

    Declaration

    Swift

    func build() throws -> ViewController
  • execute() Extension method

    Prepares the Factory and builds its UIViewController

    Declaration

    Swift

    func execute() throws -> ViewController