One Logo Pool Ball
SwiftUICore · IOS API REFERENCE

ViewBuilder

struct · iOS 13.0+ · SDK 27.1

@resultBuilder struct ViewBuilder

A custom parameter attribute that constructs views from closures. When you build your project in Xcode 26 and earlier, use ``ViewBuilder`` as a parameter attribute for view-producing closure parameters, allowing those closures to provide multiple child views. For example, the following `contextMenu` function accepts a closure that produces one or more views via the view builder. func contextMenu<MenuItems: View>( @ViewBuilder menuItems: () -> MenuItems ) -> some View Clients of this function can use multiple-statement closures to provide several child views, as the following example shows: myView.contextMenu { Text("Cut") Text("Copy") Text("Paste") if isSymbol { Text("Jump to Definition") } } When you build in Xcode 27 and later for any version of SwiftUI, the system constructs type-agnostic content from `ViewBuilder` closures, and doesn't restrict the types you use in closures to conform to ``View``. Mark closures with the type alias ``ContentBuilder`` instead to indicate where your code expects this behavior. For more information, see ``ContentBuilder``.

Members (6)

static · iOS 13.0+

buildBlock

TypeScript
static buildBlock(): EmptyView
Swift declaration
@export(implementation) static func buildBlock() -> EmptyContent

Builds an empty content from a block containing no statements.

static · iOS 13.0+

buildBlock

TypeScript
static buildBlock33579(content: unknown): unknown
Swift declaration
@export(implementation) static func buildBlock<Content>(_ content: Content) -> Content

Passes a single piece of content written as a child view through unmodified. An example of a single item written as child content is `{ Text("Hello") }`.

static · iOS 13.0+

buildEither

TypeScript
static buildEitherFirst(first: unknown): SDKHandle
Swift declaration
@export(implementation) static func buildEither<TrueContent, FalseContent>(first: TrueContent) -> _ConditionalContent<TrueContent, FalseContent>

Produces content for a conditional statement in a multi-statement closure when the condition is true.

static · iOS 13.0+

buildEither

TypeScript
static buildEitherSecond(second: unknown): SDKHandle
Swift declaration
@export(implementation) static func buildEither<TrueContent, FalseContent>(second: FalseContent) -> _ConditionalContent<TrueContent, FalseContent>

Produces content for a conditional statement in a multi-statement closure when the condition is false.

static · iOS 14.0+

buildLimitedAvailability

TypeScript
static buildLimitedAvailability(content: SDKHandle): AnyView
Swift declaration
@export(implementation) static func buildLimitedAvailability<Content>(_ content: Content) -> AnyView where Content : View

Processes view content for a conditional compiler-control statement that performs an availability check.

static · iOS 13.0+

buildIf

TypeScript
static buildIf(content?: (unknown) | null): (unknown) | null
Swift declaration
@export(implementation) static func buildIf<Content>(_ content: Content?) -> Content?

Produces optional content for conditional statements in multi-statement closures that's only included when the condition evaluates to true.

Skipped declarations

2 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

ViewBuilder.buildBlock(_:)

Swift parameter packs cannot cross the bridge.

ViewBuilder.buildBlock(_:)

Swift parameter packs cannot cross the bridge.

All SwiftUICore types →