TechnologiesSwiftUI

TableColumnCustomizationBehavior struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A set of customization behaviors of a column that a table can offer to

How it works

TableColumnCustomizationBehavior describes the kinds of customization a person is allowed to perform on an individual column of a Table — namely whether they may reorder it or hide it. SwiftUI's tables let people rearrange and toggle columns interactively, but some columns are structural and shouldn't move or disappear; this type is how you express that policy per column. Reach for it through the customizationBehavior(_:) modifier when you want a column pinned in place, hidden from the customization menu, or fully participating in reordering and visibility changes.

  1. Choose a behavior from the standard cases

    TableColumnCustomizationBehavior is a value with a small set of options that name what's permitted: .all allows both reordering and visibility toggling, .reorderable permits moving the column but not hiding it, .visibility permits hiding but not moving, and .disabled locks the column out of customization entirely. In the example the Name column opts into .reorderable while the Count column uses .disabled.

  2. Apply it with customizationBehavior(_:)

    You attach a behavior to a column by calling the customizationBehavior(_:) modifier on a TableColumn. This is where the symbol plugs in — each column declares its own policy independently, so .customizationBehavior(.reorderable) on the "Name" column and .customizationBehavior(.disabled) on the "Count" column govern only those columns.

  3. Bind a TableColumnCustomization to persist the state

    Per-column behaviors only matter when the table actually tracks customization, which it does through a TableColumnCustomization value bound into the Table. Here @State private var customization = TableColumnCustomization<Fruit>() holds the live order and visibility, and it's passed as columnCustomization: $customization so the user's allowed changes are recorded and restored.

  4. Mix behaviors across the column set

    Because the behavior is set per column rather than for the whole table, you can compose a layout where some columns rearrange freely and others stay fixed. The Table(fruits, columnCustomization: $customization) in the example pairs a .reorderable column with a .disabled one, so the user can move "Name" around the locked "Count" column but can never relocate or hide "Count" itself.

Try it — Change the "Count" column's .customizationBehavior(.disabled) to .customizationBehavior(.visibility) and watch it become hideable from the customization menu while still refusing to be dragged into a new position.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

TableColumnCustomizationBehavior.swift
struct TableColumnCustomizationBehaviorDemo: View {
    struct Fruit: Identifiable {
        let id = UUID()
        let name: String
        let count: Int
    }
    let fruits = [
        Fruit(name: "Apple", count: 12),
        Fruit(name: "Banana", count: 8),
        Fruit(name: "Cherry", count: 24)
    ]
    @State private var customization = TableColumnCustomization<Fruit>()
    var body: some View {
        Table(fruits, columnCustomization: $customization) {
            TableColumn("Name", value: \.name)
                .customizationBehavior(.reorderable)
            TableColumn("Count") { fruit in
                Text("\(fruit.count)")
            }
            .customizationBehavior(.disabled)
        }
        .padding()
    }
}
Live preview
Name Count Apple Banana Cherry
Name Count Apple Banana Cherry
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →