How it works
AutomaticTableStyle is the default presentation that SwiftUI applies to a Table when you don't request a specific look. Rather than describing fixed visuals, it defers to the platform and the surrounding context, resolving to whatever table appearance is conventional for the current environment. Reach for it when you want a table that simply looks correct wherever it runs, and let SwiftUI choose the layout, header treatment, and row styling on your behalf.
Apply the style with tableStyle(.automatic)
AutomaticTableStyle conforms to TableStyle, and you install it through the tableStyle(_:) modifier using the .automatic shorthand. In the example,
.tableStyle(.automatic)attaches the style to theTable(fruits)view, telling SwiftUI to render that table with its default, context-appropriate appearance.Provide rows from an identifiable collection
The style works on whatever data the Table is built from, so its only structural requirement is that each row be uniquely identifiable. Here the
Fruitstruct conforms toIdentifiablevia itsidproperty, andTable(fruits)uses that identity to lay out one row per element under the automatic style.Describe the table's shape with TableColumn
AutomaticTableStyle styles the columns you declare, it doesn't create them. Each
TableColumnin the builder defines a heading and the value to show, as withTableColumn("Name", value: \.name)andTableColumn("Price", value: \.price). The automatic style then decides how those headers and cells are presented.Rely on .automatic as the resolved default
Because .automatic is what a Table already uses when no style is specified, writing
.tableStyle(.automatic)makes that default explicit and overridable. It is the value SwiftUI falls back to, so any table without an explicit style behaves as if AutomaticTableStyle were applied.
.tableStyle(.automatic) for .tableStyle(.inset) to see how the automatic default differs from an explicitly chosen table style.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 AutomaticTableStyleDemo: View {
struct Fruit: Identifiable {
let id = UUID()
let name: String
let price: String
}
let fruits = [
Fruit(name: "Apple", price: "$1.20"),
Fruit(name: "Banana", price: "$0.50"),
Fruit(name: "Cherry", price: "$3.80")
]
var body: some View {
Table(fruits) {
TableColumn("Name", value: \.name)
TableColumn("Price", value: \.price)
}
.tableStyle(.automatic)
.padding()
}
}