<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 12.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/TableColumnContent",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI18TableColumnContentP"
  },
  "title" : "TableColumnContent"
}
-->

# TableColumnContent

A type used to represent columns within a table.

```
@MainActor @preconcurrency protocol TableColumnContent<TableRowValue, TableColumnSortComparator>
```

## Overview

This type provides the body content of the column, as well as the types
of the column’s row values and the comparator used to sort rows.

You can factor column content out into separate types or properties, or
by creating a custom type conforming to `TableColumnContent`.

```
var body: some View {
    Table(people, selection: $selectedPeople, sortOrder: $sortOrder) {
        nameColumns

        TableColumn("Location", value: \.location) {
            LocationView($0.location)
        }
    }
}

@TableColumnBuilder<Person, KeyPathComparator<Person>>
private var nameColumns: some TableColumnContent<
    Person, KeyPathComparator<Person>
> {
    TableColumn("First Name", value: \.firstName) {
        PrimaryColumnView(person: $0)
    }
    TableColumn("Last Name", value: \.lastName)
    TableColumn("Nickname", value: \.nickname)
}
```

The above example factors three table columns into a separate computed
property that has an opaque type. The property’s primary associated
type `TableRowValue` is a `Person` and its associated type
`TableColumnSortComparator` is a key comparator for the `Person` type.

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 column body

[`var tableColumnBody: Self.TableColumnBody`](/documentation/SwiftUI/TableColumnContent/tableColumnBody-swift.property)

The composition of content that comprise the table column content.

[`associatedtype TableColumnBody : TableColumnContent`](/documentation/SwiftUI/TableColumnContent/TableColumnBody-swift.associatedtype)

The type of content representing the body of this table column content.

### Defining the row value

[`associatedtype TableRowValue : Identifiable = Self.TableColumnBody.TableRowValue`](/documentation/SwiftUI/TableColumnContent/TableRowValue)

The type of value of rows presented by this column content.

### Defining the comparator

[`associatedtype TableColumnSortComparator : SortComparator = Self.TableColumnBody.TableColumnSortComparator`](/documentation/SwiftUI/TableColumnContent/TableColumnSortComparator)

The type of sort comparator associated with this table column content.

### Configuring the content

[`func alignment(TableColumnAlignment) -> some TableColumnContent<Self.TableRowValue, Self.TableColumnSortComparator>`](/documentation/SwiftUI/TableColumnContent/alignment(_:))

Sets the alignment of the column, applying to both its column header
label and the row view content for that column.

[`func customizationID(String) -> some TableColumnContent<Self.TableRowValue, Self.TableColumnSortComparator>`](/documentation/SwiftUI/TableColumnContent/customizationID(_:))

Sets the identifier to be associated with a column when persisting its
state with `TableColumnCustomization`.

[`func defaultVisibility(Visibility) -> some TableColumnContent<Self.TableRowValue, Self.TableColumnSortComparator>`](/documentation/SwiftUI/TableColumnContent/defaultVisibility(_:))

Sets the default visibility of a table column.

[`func disabledCustomizationBehavior(TableColumnCustomizationBehavior) -> some TableColumnContent<Self.TableRowValue, Self.TableColumnSortComparator>`](/documentation/SwiftUI/TableColumnContent/disabledCustomizationBehavior(_:))

Sets the disabled customization behavior for a table column.

## Relationships

### Conforming Types

[`TupleTableColumnContent`](/documentation/SwiftUI/TupleTableColumnContent)

[`TableColumnForEach`](/documentation/SwiftUI/TableColumnForEach)

[`TableColumn`](/documentation/SwiftUI/TableColumn)

[`Group`](/documentation/SwiftUI/Group)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)