Skip to content

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

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

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:)

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

buildViewController()

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:)

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:)

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.