AnyViewModel

public protocol AnyViewModel

You conform to the AnyViewModel protocol to define the model that is used by your view to bind to properties and logic needed and to handle its lifecycle. Implement the required ViewType property to provide the view type.

Associatedtypes

  • The type of view for this view model.

    When you create a custom view model, Swift infers this type from the generic V type property.

    Declaration

    Swift

    associatedtype ViewType : MwxView

Coordinators

  • The coordinator managing this view model.

    Declaration

    Swift

    var coordinator: AnyCoordinator? { get set }
  • The tab coordinators managed by the managing coordinator of this view model.

    Declaration

    Swift

    var tabCoordinators: [AnyCoordinator]? { get set }

Input & Output

  • The input factory used to generate inputs in this view model.

    Declaration

    Swift

    var output: MwxOutput { get set }
  • The input used to initialize this view model and passed from presenting view models.

    Declaration

    Swift

    var input: MwxInput { get set }

Initialization

  • Creates an instance of this view model. Required.

    Declaration

    Swift

    init()

Lifecycle

  • The function called when the view for this view model appears each time.

    Declaration

    Swift

    func didAppear()
  • The function called when the view for this view model disappears each time.

    Declaration

    Swift

    func didDisappear()

Navigation

  • Call this function to pop the view for this view model if navigationly pushed.

    Note

    Only works with link coordinators.

    Declaration

    Swift

    func pop()
  • Call this function to dismiss the view for this view model if presented modally.

    Note

    Only works with sheet coordinators.

    Declaration

    Swift

    func dismiss()
  • Call this function to select the tab for this view model if tabs are defined.

    Note

    Only works if tab coordinators defined.

    Declaration

    Swift

    func select(tab selection: Int)

    Parameters

    selection

    A Int indicates the selected tab index.

Coordinator Factory

  • root() Extension method

    Call this function to create an instance of a coordinator of root presentation for this view Model type.

    Declaration

    Swift

    static func root()

    Return Value

    The coordinator instance of this view model type.

  • tab(_:) Extension method

    Call this function to create an instance of a coordinator of tab presentation for this view Model type.

    Declaration

    Swift

    static func tab<V>(_ sender: MwxViewModel<V>) -> MwxCoordinator<Self> where V : MwxView

    Parameters

    sender

    A generic MwxViewModel indicates the sender view model for this request.

    Return Value

    The coordinator instance of this view model type.

  • link(_:) Extension method

    Call this function to create an instance of a coordinator of link presentation for this view Model type.

    Declaration

    Swift

    static func link<V>(_ sender: MwxViewModel<V>) -> MwxCoordinator<Self> where V : MwxView

    Parameters

    sender

    A generic MwxViewModel indicates the sender view model for this request.

    Return Value

    The coordinator instance of this view model type.

  • sheet(_:) Extension method

    Call this function to create an instance of a coordinator of sheet presentation for this view Model type.

    Declaration

    Swift

    static func sheet<V>(_ sender: MwxViewModel<V>) -> MwxCoordinator<Self> where V : MwxView

    Parameters

    sender

    A generic MwxViewModel indicates the sender view model for this request.

    Return Value

    The coordinator instance of this view model type.

  • Creates an instance of a coordinator for this view Model type.

    Declaration

    Swift

    static func coordinator(presentation: MwxPresentation,
                            managingCoordinator: AnyCoordinator? = nil) -> MwxCoordinator<Self>

    Parameters

    presentation

    A MwxPresentation indicates the presentation of the coordinator.

    managingCoordinator

    A AnyCoordinator indicates managing coordinator of the coordinator.

    Return Value

    The coordinator instance of this view model type.

View Factory

  • make() Extension method

    Call this function to create the view and register its corresponding view model prototype.

    Declaration

    Swift

    static func make() -> some MwxView

    Return Value

    The view for this view model.