<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macOS: 26.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/OpenImmersiveSpaceAction",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI24OpenImmersiveSpaceActionV"
  },
  "title" : "OpenImmersiveSpaceAction"
}
-->

# OpenImmersiveSpaceAction

An action that presents an immersive space.

```
@MainActor struct OpenImmersiveSpaceAction
```

## Overview

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

On macOS, this may be used to open a remote immersive space declared
with [`RemoteImmersiveSpace`](/documentation/SwiftUI/RemoteImmersiveSpace). When your app opens a remote immersive
space, the system may ask the user for a preferred device with which to
display the content.

For example, you can define a button that opens a specified planet in an
immersive space:

```
@main
struct SolarSystemApp: App {
    var body: some Scene {
        ImmersiveSpace(for: Planet.ID.self) { $planetID in
            // ...
        }
    }
}

struct ShowPlanetButton: View {
    var planet: Planet
    @Environment(\.openImmersiveSpace) private var openImmersiveSpace

    var body: some View {
        Button("Show \(planet.name)") {
            Task {
                await openImmersiveSpace(value: planet.ID)
            }
        }
    }
}
```

You indicate which immersive space to open by providing one of the
following:

- A string identifier that you pass through the `id` parameter.
- A `value` parameter that has a type that matches the type that you
  specify in the space’s initializer, as in the above example.
- Both an identifier and a value. This enables you to define multiple
  spaces that take input values of the same type and distinguish them
  by their string identifiers.

The call is asynchronous and returns after presenting the space or if
an error occurs. You can check for errors by inspecting the call’s
return value, which is of type [`OpenImmersiveSpaceAction.Result`](/documentation/SwiftUI/OpenImmersiveSpaceAction/Result).
For example, the call returns an error if you already have an immersive
space open, because the system enables only one space to be open at a
time.

If you provide a value when you open the space, the scene’s trailing
closure receives a binding to the value that you provide.
For best performance, use lightweight data for the presentation value.
For structured model values that conform to
<doc://com.apple.documentation/documentation/Swift/Identifiable>,
the value’s identifier makes a good presentation value, like
the `planet.ID` value in the above code.

## Topics

### Calling the action

[`func callAsFunction(id: String) async -> OpenImmersiveSpaceAction.Result`](/documentation/SwiftUI/OpenImmersiveSpaceAction/callAsFunction(id:))

Presents an immersive space for the scene with the specified identifier.

[`func callAsFunction<D>(id: String, value: D) async -> OpenImmersiveSpaceAction.Result`](/documentation/SwiftUI/OpenImmersiveSpaceAction/callAsFunction(id:value:))

Presents the immersive space that your app defines for the specified
identifier and that handles the type of the presented value.

[`func callAsFunction<D>(value: D) async -> OpenImmersiveSpaceAction.Result`](/documentation/SwiftUI/OpenImmersiveSpaceAction/callAsFunction(value:))

Presents the immersive space that handles the type of the presented
value.

### Getting the result

[`enum Result`](/documentation/SwiftUI/OpenImmersiveSpaceAction/Result)

The outcome of an attempt to open an immersive space.

### Instance Methods

[`func callAsFunction(foveatedStreaming: FoveatedStreamingSession) async -> OpenImmersiveSpaceAction.Result`](/documentation/SwiftUI/OpenImmersiveSpaceAction/callAsFunction(foveatedStreaming:))

Presents the immersive space that your app defines for the specified foveated streaming session.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

---

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)