TechnologiesSwiftUI

TabViewCustomization struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The customizations a person makes to an adaptable sidebar tab view.

How it works

TabViewCustomization is a value type that captures the user's personalization of a tab bar or sidebar — which tabs are visible, hidden, or reordered — so those choices survive across launches. Reach for it when you adopt an adaptable tab layout (such as the sidebar that appears on iPad) and want people to tailor it to their workflow rather than accept a fixed arrangement. Because it conforms to Codable, you persist its state yourself, and SwiftUI reads and writes it as the user rearranges the interface.

  1. Hold the customization in persistent state

    Create a single TabViewCustomization value and own it where it can outlive view updates and be saved. The example stores it in @State private var customization = TabViewCustomization(); in a real app you would back this with something like @AppStorage or your own persistence so the layout is restored on the next launch.

  2. Bind it to the tab view with tabViewCustomization(_:)

    The .tabViewCustomization($customization) modifier connects your stored value to the TabView. It takes a binding, so SwiftUI both reads the saved arrangement to lay out the tabs and writes back any changes the user makes through the interface.

  3. Give each tab a stable identity with customizationID(_:)

    TabViewCustomization keys its per-tab settings by identifier, so every customizable tab needs a stable, unique string. Here each Tab is tagged with .customizationID("tab.home"), .customizationID("tab.alerts"), and .customizationID("tab.browse"); these IDs are how the recorded visibility and order map back to the right tab when state is restored.

  4. Use an adaptable style so customization is reachable

    Customization affordances surface in layouts that present an editable sidebar. Applying .tabViewStyle(.sidebarAdaptable) lets the TabView show a sidebar where it has room, giving people a place to reorder and hide the tabs whose changes TabViewCustomization records.

  5. Persist the recorded state via Codable

    TabViewCustomization conforms to Codable, so you can encode the customization value to durable storage and decode it at startup. SwiftUI keeps the value updated as the user edits the layout; saving and reloading that value is what makes their arrangement stick between sessions.

Try it — Change one tab's identifier, for example rename .customizationID("tab.browse") to a different string, and the previously saved visibility or order for that tab will no longer apply, since the customization state is keyed by ID.

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.

TabViewCustomization.swift
struct TabViewCustomizationDemo: View {
    @State private var customization = TabViewCustomization()

    var body: some View {
        TabView {
            Tab("Home", systemImage: "house") {
                Text("Home")
            }
            .customizationID("tab.home")

            Tab("Alerts", systemImage: "bell") {
                Text("Alerts")
            }
            .customizationID("tab.alerts")

            Tab("Browse", systemImage: "square.grid.2x2") {
                Text("Browse")
            }
            .customizationID("tab.browse")
        }
        .tabViewStyle(.sidebarAdaptable)
        .tabViewCustomization($customization)
    }
}
Live preview
Home Home Alerts Browse
Home Home Alerts Browse
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →