TechnologiesSwiftUI

AutomaticTableStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The default table style in the current context.

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.

  1. 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 the Table(fruits) view, telling SwiftUI to render that table with its default, context-appropriate appearance.

  2. 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 Fruit struct conforms to Identifiable via its id property, and Table(fruits) uses that identity to lay out one row per element under the automatic style.

  3. Describe the table's shape with TableColumn

    AutomaticTableStyle styles the columns you declare, it doesn't create them. Each TableColumn in the builder defines a heading and the value to show, as with TableColumn("Name", value: \.name) and TableColumn("Price", value: \.price). The automatic style then decides how those headers and cells are presented.

  4. 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.

Try it — Swap .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.

AutomaticTableStyle.swift
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()
    }
}
Live preview
Name Price Apple $1.20 Banana $0.50 Cherry $3.80
Name Price Apple $1.20 Banana $0.50 Cherry $3.80
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →