How it works
InsetTableStyle is the table style that insets a Table's rows from its leading and trailing edges, giving the data a framed, contained appearance rather than running edge to edge. It conforms to the TableStyle protocol, so you don't construct or interact with it directly — you select it through the tableStyle(_:) modifier and let SwiftUI apply the platform's inset layout to the rows, headers, and column dividers. Reach for it when a table sits inside other content and you want its rows visually grouped and indented to read as a distinct unit.
Conforms to the TableStyle protocol
InsetTableStyleis one of the concrete types that adoptTableStyle, the protocol SwiftUI uses to describe a table's overall appearance. As a style value it carries no configuration of its own; its job is to define how aTable's rows are arranged and inset when the system lays them out.Apply it with the .inset shorthand
Rather than naming the type, you reach
InsetTableStylethrough the static.insetmember onTableStyle. In the example,.tableStyle(.inset)resolves to this style, which is the dot-shorthand the framework provides so you can request the inset appearance without writing the full type name.Set it through the tableStyle(_:) modifier
The
tableStyle(_:)view modifier is where the style plugs in: it takes aTableStylevalue and applies it to theTableit modifies, along with any tables nested in that view's hierarchy. HereTable(people)is followed by.tableStyle(.inset), which handsInsetTableStyleto the table built from theTableColumndefinitions for"Name"and"Role".Affects the Table's row and column layout
Once applied, the style governs how the table's content is positioned — its rows are pulled in from the container's edges and presented as a grouped block. The columns declared by
TableColumn("Name", value: \.name)andTableColumn("Role", value: \.role)are unchanged in content; only their inset framing within the surrounding view responds to the chosen style.
.tableStyle(.inset) to .tableStyle(.bordered) and watch the rows lose their inset framing and span the full width with full-grid borders instead.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 InsetTableStyleDemo: View {
struct Person: Identifiable {
let id = UUID()
let name: String
let role: String
}
private let people = [
Person(name: "Ada Lovelace", role: "Engineer"),
Person(name: "Alan Turing", role: "Scientist"),
Person(name: "Grace Hopper", role: "Admiral")
]
var body: some View {
Table(people) {
TableColumn("Name", value: \.name)
TableColumn("Role", value: \.role)
}
.tableStyle(.inset)
.padding()
}
}