Contents

init(_:)

Creates an instance that uniquely identifies and creates table rows across updates based on the identity of the underlying data.

Declaration

nonisolated init(_ data: Data) where ID == Data.Element.ID, Content == TableRow<Data.Element>, Data.Element : Identifiable

Parameters

  • data:

    The identified data that the Foreach instance uses to create table rows dynamically.

Discussion

The following example creates a Person type that conforms to Identifiable, and an array of this type called people. A ForEach instance iterates over the array, producing new TableRow instances implicitly.

private struct Person: Identifiable {
    var id = UUID()
    var name: String
}

@State private var people: [Person] = /* ... */

Table(of: Person.self) {
    TableColumn("ID", value: \.id.uuidString)
    TableColumn("Name", value: \.name)
} rows: {
    Section("Team") {
        /* This is equivalent to the line below:
        ForEach(people) { TableRow($0) }
        */
        ForEach(people)
    }
}

See Also

Creating a collection