<!--
{
  "availability" : [
    "macOS: 14.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/OpenSettingsAction",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI18OpenSettingsActionV"
  },
  "title" : "OpenSettingsAction"
}
-->

# OpenSettingsAction

An action that presents the settings scene for an app.

```
@MainActor @preconcurrency struct OpenSettingsAction
```

## Overview

Use the [`openSettings`](/documentation/SwiftUI/EnvironmentValues/openSettings) environment value to get the
instance of this structure for a given [`Environment`](/documentation/SwiftUI/Environment). Then call the
instance to open a window. You call the instance directly because it
defines a [`callAsFunction()`](/documentation/SwiftUI/OpenSettingsAction/callAsFunction()) method that Swift calls
when you call the instance.

For example, you can define a button that opens the settings window to
a particular tab:

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

struct SettingsView: View {
    @AppStorage("selectedSettingsTab")
    private var selectedSettingsTab = SettingsTab.general

    var body: some View {
        TabView(selection: $selectedSettingsTab) {
            GeneralSettings()
            AdvancedSettings()
        }
    }
}

struct AdvancedSettingsButton: View {
    @AppStorage("selectedSettingsTab")
    private var selectedSettingsTab = SettingsTab.general

    @Environment(\.openSettings) private var openSettings

    var body: some View {
        Button("Open Advanced Settings…") {
            selectedSettingsTab = .advanced
            openSettings()
        }
    }
}

enum SettingsTab: Int {
    case general
    case advanced
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)