Skip to content

STRUCT

ViewControllerDescription

public struct ViewControllerDescription

A ViewControllerDescription acts as a “recipe” for building and updating a specific UIViewController. It describes how to create and later update a given view controller instance, without creating one itself. This means it is a lightweight currency you can create and pass around to describe a view controller, without needing to create one.

The most common use case for a ViewControllerDescription is to return it from your Screen’s viewControllerDescription(environment:) method. The WorkflowUI machinery (or your custom container view controller) will then use this view controller description to create or update the on-screen presented view controller.

As a creator of a custom container view controller, you will usually pass this view controller description to a DescribedViewController, which will internally create and manage the described view controller for its current view controller description. However, you can also directly invoke the public methods such as buildViewController(), update(viewController:), if you are manually managing your own view controller hierarchy.

Properties

performInitialUpdate

public var performInitialUpdate: Bool

If an initial call to update(viewController:) will be performed when the view controller is created. Defaults to true.

Note

When creating container view controllers that contain other view controllers (eg, a navigation stack), you usually want to set this value to false to avoid duplicate updates to your children if they are created in init.

kind

public let kind: KindIdentifier

Describes the UIViewController type that backs the ViewControllerDescription in a way that is Equatable and Hashable. When implementing view controller updating and diffing, you can use this type to identify if the backing view controller type changed.

Methods

init(performInitialUpdate:type:environment:build:update:)

public init<VC: UIViewController>(
    performInitialUpdate: Bool = true,
    type: VC.Type = VC.self,
    environment: ViewEnvironment,
    build: @escaping () -> VC,
    update: @escaping (VC) -> Void
)

Constructs a view controller description by providing closures used to build and update a specific view controller type.

  • Parameters:
  • performInitialUpdate: If an initial call to update(viewController:) will be performed when the view controller is created. Defaults to true.

  • environment: The ViewEnvironment that should be injected above the described view controller for ViewEnvironmentUI environment propagation. This is typically passed in from a Screen in its viewControllerDescription(environment:) method.

  • type: The type of view controller produced by this description. Typically, should should be able to omit this parameter, but in cases where type inference has trouble, it’s offered as an escape hatch.

  • build: Closure that produces a new instance of the view controller

  • update: Closure that updates the given view controller

Parameters

Name Description
performInitialUpdate If an initial call to update(viewController:) will be performed when the view controller is created. Defaults to true.
environment The ViewEnvironment that should be injected above the described view controller for ViewEnvironmentUI environment propagation. This is typically passed in from a Screen in its viewControllerDescription(environment:) method.
type The type of view controller produced by this description. Typically, should should be able to omit this parameter, but in cases where type inference has trouble, it’s offered as an escape hatch.
build Closure that produces a new instance of the view controller
update Closure that updates the given view controller

buildViewController()

public func buildViewController() -> UIViewController

Construct and update a new view controller as described by this view controller description. The view controller will be updated before it is returned, so it is fully configured and prepared for display.

canUpdate(viewController:)

public func canUpdate(viewController: UIViewController) -> Bool

If the given view controller is of the correct type to be updated by this view controller description.

If your view controller type can change between updates, call this method before invoking update(viewController:).

update(viewController:)

public func update(viewController: UIViewController)

Update the given view controller with the content from the view controller description.

  • Parameters:
  • viewController: The view controller to update.

Note

You must pass a view controller previously created by a compatible ViewControllerDescription that passes canUpdate(viewController:). Failure to do so will result in a fatal precondition.

Parameters

Name Description
viewController The view controller to update.