Contents

AppIntentControlValueProvider

A type that uses a custom intent to provide a value to a control template.

Declaration

protocol AppIntentControlValueProvider

Overview

The provider quickly and cheaply prepares a synchronous value to be shown while previewing the control in the add sheet. When the actual control needs to be rendered, the actual, current value will be fetched asynchronously.

The provider prepares these values using an intent containing user-editable parameters.

For instance, a control that opens and closes various doors in a user’s home may show a preview of the door being closed. When the actual control is rendered, the control may fetch the configured door’s status from the cloud:

struct DoorValueProvider: AppIntentControlValueProvider {
    func previewValue(configuration: SelectDoorIntent) -> Door {
        Door(id: configuration.doorId, isOpen: false)
    }

    func currentValue(configuration: SelectDoorIntent) async -> Door {
        let isOpen = await DoorManager.shared
            .status(doorId: configuration.doorId)
        return Door(id: configuration.doorId, isOpen: isOpen)
    }
}

Topics

Associated Types

Instance Methods

See Also

Previews