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.
Choose a behavior from the standard cases
TableColumnCustomizationBehavioris a value with a small set of options that name what's permitted:.allallows both reordering and visibility toggling,.reorderablepermits moving the column but not hiding it,.visibilitypermits hiding but not moving, and.disabledlocks the column out of customization entirely. In the example the Name column opts into.reorderablewhile the Count column uses.disabled.Apply it with customizationBehavior(_:)
You attach a behavior to a column by calling the
customizationBehavior(_:)modifier on aTableColumn. 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.Bind a TableColumnCustomization to persist the state
Per-column behaviors only matter when the table actually tracks customization, which it does through a
TableColumnCustomizationvalue bound into theTable. Here@State private var customization = TableColumnCustomization<Fruit>()holds the live order and visibility, and it's passed ascolumnCustomization: $customizationso the user's allowed changes are recorded and restored.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.reorderablecolumn with a.disabledone, so the user can move"Name"around the locked"Count"column but can never relocate or hide"Count"itself.
"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.
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()
}
}