---
title: OpenWindowAction
framework: swiftui
role: symbol
role_heading: Structure
path: swiftui/openwindowaction
---

# OpenWindowAction

An action that presents a window.

## Declaration

```swift
@MainActor @preconcurrency struct OpenWindowAction
```

## Overview

Overview Use the openWindow environment value to get the instance of this structure for a given Environment. Then call the instance to open a window. You call the instance directly because it defines a callAsFunction(id:) method that Swift calls when you call the instance. For example, you can define a button that opens a new mail viewer window: @main struct Mail: App {     var body: some Scene {         WindowGroup(id: "mail-viewer") {             MailViewer()         }     } }

struct NewViewerButton: View {     @Environment(\.openWindow) private var openWindow

var body: some View {         Button("Open new mail viewer") {             openWindow(id: "mail-viewer")         }     } } You indicate which scene to open by providing one of the following: A string identifier that you pass through the id parameter, as in the above example. A value parameter that has a type that matches the type that you specify in the scene’s initializer. Both an identifier and a value. This enables you to define multiple window groups that take input values of the same type, like a UUID. Use the first option to target either a WindowGroup or a Window scene in your app that has a matching identifier. For a WindowGroup, the system creates a new window for the group. If the window group presents data, the system provides the default value or nil to the window’s root view. If the targeted scene is a Window, the system orders it to the front. Use the other two options to target a WindowGroup and provide a value to present. If the interface already has a window from the group that’s presenting the specified value, the system brings the window to the front. Otherwise, the system creates a new window and passes a binding to the specified value.

## Topics

### Calling the action

- [callAsFunction(id:)](swiftui/openwindowaction/callasfunction(id:).md)
- [callAsFunction(id:value:)](swiftui/openwindowaction/callasfunction(id:value:).md)
- [callAsFunction(value:)](swiftui/openwindowaction/callasfunction(value:).md)

### Structures

- [OpenWindowAction.SharingBehavior](swiftui/openwindowaction/sharingbehavior.md)

### Instance Methods

- [callAsFunction(id:sharingBehavior:)](swiftui/openwindowaction/callasfunction(id:sharingbehavior:).md)
- [callAsFunction(id:value:sharingBehavior:)](swiftui/openwindowaction/callasfunction(id:value:sharingbehavior:).md)
- [callAsFunction(value:sharingBehavior:)](swiftui/openwindowaction/callasfunction(value:sharingbehavior:).md)

## Relationships

### Conforms To

- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Opening windows

- [Presenting windows and spaces](visionos/presenting-windows-and-spaces.md)
- [supportsMultipleWindows](swiftui/environmentvalues/supportsmultiplewindows.md)
- [openWindow](swiftui/environmentvalues/openwindow.md)
- [PushWindowAction](swiftui/pushwindowaction.md)
