Contents

ControlWidgetTemplateBuilder

A custom attribute that constructs a control widget template’s body.

Declaration

@resultBuilder struct ControlWidgetTemplateBuilder

Overview

The @ControlWidgetTemplateBuilder attribute allows your control template’s body closure to produce a control template after zero or more other statements:

struct GarageDoorOpener: ControlWidget {
    var body: some ControlWidgetConfiguration {
        let kind = "com.yourcompany.GarageDoorOpener"

        StaticControlConfiguration(
            kind: kind
        ) {
            let isOpen = ...

            ControlWidgetToggle(
                "Garage Door",
                isOn: isOpen,
                action: ToggleGarageDoor()
            ) {
                Label(
                    $0 ? "Open" : "Closed",
                    systemImage: $0 ?
                        "door.garage.open" : "door.garage.closed"
                )
            }
        }
    }
}

Topics

Type Methods

See Also

Composing control widgets