TechnologiesSwiftUI

List struct

iOSmacOStvOSwatchOSvisionOSiOS 13.0+✓ renders

A container that presents rows of data arranged in a single column,

How it works

A List is a container that presents rows of data arranged in a single, scrolling column. It's the standard way to build the table- and settings-style screens common across iOS and macOS, handling scrolling, row separators, selection, and platform-appropriate styling so you don't have to assemble that behavior yourself. Reach for List whenever you have a collection of items to display as discrete, interactive rows — and prefer it over a ScrollView of stacked views when you want built-in list affordances like sections, swipe actions, and adaptive insets.

  1. Build rows from static or dynamic content

    List accepts a view builder whose contents become its rows; each top-level view inside the closure is laid out as one row. Here the closure produces rows for each grocery, so every Label rendered inside becomes a separate, separated row in the list.

  2. Generate rows over a collection with ForEach

    To turn a collection into rows, nest a ForEach inside the List and give it an identity so SwiftUI can track each row across updates. The example iterates groceries with id: \.self, producing one row per string in the array without you writing out each row by hand.

  3. Group rows into labeled sections

    A List can organize its rows into Section views, each with an optional header that the list styles as a group heading. Wrapping the rows in Section("Groceries") collects the items under a titled group, which List renders with the inset, grouped appearance the platform expects.

  4. Style row content with list-aware views

    Views placed in a row adapt to the list's layout — Label, for instance, pairs text with a leading icon and aligns naturally within the row's content margins. Each Label(item, systemImage: "cart") fills a row with a title and SF Symbol while List supplies the separators and spacing around it.

  5. Adjust presentation with a list style

    Apply the .listStyle(_:) modifier to the List to switch between presentations such as .plain, .grouped, .insetGrouped, or .sidebar without changing the row content. The example relies on the platform default, but attaching a style to the List lets you control how sections and separators are drawn.

Try it — Add a second Section("Pantry") { ... } alongside the existing Section("Groceries") inside the List to watch it space the two groups apart with their own headers.

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.

List.swift
struct ListDemo: View {
    let groceries = ["Apples", "Bread", "Coffee", "Eggs"]

    var body: some View {
        List {
            Section("Groceries") {
                ForEach(groceries, id: \.self) { item in
                    Label(item, systemImage: "cart")
                }
            }
        }
    }
}
Live preview
Groceries
Groceries
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →