Contents

TableRowContent

A type used to represent table rows.

Declaration

@MainActor @preconcurrency protocol TableRowContent<TableRowValue>

Overview

Like with the View protocol, you can create custom table row content by declaring a type that conforms to the TableRowContent protocol and implementing the required tableRowBody property.

struct GroupOfPeopleRows: TableRowContent {
    @Binding var people: [Person]

    var tableRowBody: some TableRowContent<Person> {
        ForEach(people) { person in
            TableRow(person)
                .itemProvider { person.itemProvider }
        }
        .dropDestination(for: Person.self) { destination, newPeople in
            people.insert(contentsOf: newPeople, at: destination)
        }
    }
}

This example uses an opaque result type and specifies that the primary associated type TableRowValue for the tableRowBody property is a Person. From this, SwiftUI can infer TableRowValue for the GroupOfPeopleRows structure is also Person.

A type conforming to this protocol inherits @preconcurrency @MainActor isolation from the protocol if the conformance is included in the type’s base declaration:

struct MyCustomType: Transition {
    // `@preconcurrency @MainActor` isolation by default
}

Isolation to the main actor is the default, but it’s not required. Declare the conformance in an extension to opt out of main actor isolation:

extension MyCustomType: Transition {
    // `nonisolated` by default
}

Topics

Getting the row body

Defining the row value

Managing interaction

Adding a context menu to a row

Instance Methods

See Also

Creating rows