<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/ControlWidgetTemplateBuilder",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI28ControlWidgetTemplateBuilderV"
  },
  "title" : "ControlWidgetTemplateBuilder"
}
-->

# ControlWidgetTemplateBuilder

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

```
@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

[`static func buildBlock<Content>(Content) -> some ControlWidgetTemplate`](/documentation/SwiftUI/ControlWidgetTemplateBuilder/buildBlock(_:))

Passes a single control widget template written as a child view
through unmodified.

[`static func buildExpression<Content>(Content) -> Content`](/documentation/SwiftUI/ControlWidgetTemplateBuilder/buildExpression(_:))

Builds an expression within the builder.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)