<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/WidgetBundleBuilder/buildOptional(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI19WidgetBundleBuilderV13buildOptionalyQrAA0C0_AA020_LimitedAvailabilityC6MarkerpSgFZ"
  },
  "title" : "buildOptional(_:)"
}
-->

# buildOptional(_:)

Produces an optional widget for conditional statements in multi-statement
closures that’s only visible when the condition evaluates to true.

```
@export(implementation) static func buildOptional(_ widget: (any Widget & _LimitedAvailabilityWidgetMarker)?) -> some Widget
```

## Discussion

Conditional statements in a [`WidgetBundleBuilder`](/documentation/SwiftUI/WidgetBundleBuilder) can contain an `if`
statement but not an `else` statement, and the condition can only
perform a compiler check for availability, like in the following code:

```
var body: some Widget {
    if #available(iOS 16, *) {
        WindowGroup {
            ContentView()
        }
    }
}
```

---

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)