跳转至
Structure

TupleView

A View created from a swift tuple of View values.

Declaration

@frozen struct TupleView<T> : View

Overview

TupleView is mainly used with ViewBuilder, so you don't really need to worry about it unless you're making your own view builders.

In the example below, we use this type to create a new kind of View that only displays the first view it is passed. The second view is ignored. Kind of useless? Yes. Instructive? You tell me.

struct ContentView: View {
    var body: some View {
        FirstView {
            Text("I am first 🥇")
            Text("Hey stop ignoring me ☹️")
        }
    }
}

struct FirstView<First: View, Second: View>: View {
    let first: First

    init(@ViewBuilder content: () -> TupleView<(First, Second)>) {
        let views = content().value
        first = views.0
    }

    var body: some View {
        first
    }
}
A screenshot displaying a single text view that reads "I am first" in the center of the screen. The display should show two text views, but the view created only displays the first view it's passed.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Initializer

init(_:) Creates a tuple view.


Type Alias

Body The type of view representing the body of this view.


Instance Property

value The tuple of views in the TupleView.