Structure

ViewBuilder

A custom parameter attribute that constructs views from closures. あるあつらえのパラメータ属性、それはビューをクロージャから組み立てるものです。

Declaration 宣言

@resultBuilder struct ViewBuilder

Overview 概要

You typically use ViewBuilder as a parameter attribute for child 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 shown in the following example: この関数のクライアントは、複数文のクロージャを使って幾つかの子ビューを生み出せます、以下の例で示されるように:


myView.contextMenu {
    Text("Cut")
    Text("Copy")
    Text("Paste")
    if isSymbol {
        Text("Jump to Definition")
    }
}

Topics 話題

Building Content

See Also 参照

View Composition