TableColumn
A column that displays a view for each row in a table.
Declaration
struct TableColumn<RowValue, Sort, Content, Label> where RowValue : Identifiable, Sort : SortComparator, Content : View, Label : ViewOverview
You create a column with a label, content view, and optional key path. The table calls the content view builder with the value for each row in the table. The column uses a key path to map to a property of each row value, which sortable tables use to reflect the current sort order.
The following example creates a sortable column for a table with Person rows, displaying each person’s given name:
TableColumn("Given name", value: \.givenName) { person in
Text(person.givenName)
}For the common case of String properties, you can use the convenience initializer that doesn’t require an explicit content closure and displays that string verbatim as a Text view. This means you can write the previous example as:
TableColumn("Given name", value: \.givenName)Topics
Creating an unsortable column
Creating a sortable column
init(_:value:content:)init(_:value:comparator:)init(_:value:comparator:content:)init(_:sortUsing:content:)