Files
antigravity-skills-reference/skills/swiftui-ui-patterns/references/macos-settings.md
sickn33 d2be634870 feat(skills): Import curated Apple workflow skills
Add fourteen skills from Dimillian/Skills, integrate the merged Snowflake and WordPress updates into the maintainer sync, and refresh registry metadata, attributions, walkthrough notes, and the 8.9.0 release notes while keeping validation warnings within budget.
2026-03-25 11:53:08 +01:00

2.0 KiB
Raw Blame History

macOS Settings

Intent

Use this when building a macOS Settings window backed by SwiftUI's Settings scene.

Core patterns

  • Declare the Settings scene in the App and compile it only for macOS.
  • Keep settings content in a dedicated root view (SettingsView) and drive values with @AppStorage.
  • Use TabView to group settings sections when you have more than one category.
  • Use Form inside each tab to keep controls aligned and accessible.
  • Use OpenSettingsAction or SettingsLink for in-app entry points to the Settings window.

Example: settings scene

@main
struct MyApp: App {
  var body: some Scene {
    WindowGroup {
      ContentView()
    }
    #if os(macOS)
    Settings {
      SettingsView()
    }
    #endif
  }
}

Example: tabbed settings view

@MainActor
struct SettingsView: View {
  @AppStorage("showPreviews") private var showPreviews = true
  @AppStorage("fontSize") private var fontSize = 12.0

  var body: some View {
    TabView {
      Form {
        Toggle("Show Previews", isOn: $showPreviews)
        Slider(value: $fontSize, in: 9...96) {
          Text("Font Size (\(fontSize, specifier: "%.0f") pts)")
        }
      }
      .tabItem { Label("General", systemImage: "gear") }

      Form {
        Toggle("Enable Advanced Mode", isOn: .constant(false))
      }
      .tabItem { Label("Advanced", systemImage: "star") }
    }
    .scenePadding()
    .frame(maxWidth: 420, minHeight: 240)
  }
}

Skip navigation

  • Avoid wrapping SettingsView in a NavigationStack unless you truly need deep push navigation.
  • Prefer tabs or sections; Settings is already presented as a separate window and should feel flat.
  • If you must show hierarchical settings, use a single NavigationSplitView with a sidebar list of categories.

Pitfalls

  • Dont reuse iOS-only settings layouts (full-screen stacks, toolbar-heavy flows).
  • Avoid large custom view hierarchies inside Form; keep rows focused and accessible.