<!--
{
  "availability" : [
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/OpenWindowAction/callAsFunction(value:sharingBehavior:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI16OpenWindowActionV14callAsFunction5value15sharingBehavioryx_AC07SharingK0VtYaKSeRzSERzSHRzlF"
  },
  "title" : "callAsFunction(value:sharingBehavior:)"
}
-->

# callAsFunction(value:sharingBehavior:)

Opens a window defined by a window group that presents the type of
the specified value, using the specified sharingBehavior.

```
@MainActor func callAsFunction<D>(value: D, sharingBehavior: OpenWindowAction.SharingBehavior) async throws where D : Decodable, D : Encodable, D : Hashable
```

## Discussion

If sharingBehavior is requested or required, the window is shared if there is
an available sharingSession and the person using your app confirms the offer to share.
If sharingBehavior is requested and the window is not shared, it is opened normally.
If sharingBehavior is required and the window is not shared, it is not opened,
and an error is thrown.
Regardless of sharingBehavior, an error is thrown if the window fails to open.

Don’t call this method directly. SwiftUI calls it when you
call the [`openWindow`](/documentation/SwiftUI/EnvironmentValues/openWindow) action with a value:

```
try await openWindow(value: message.id,
sharingBehavior: .requested)
```

For information about how Swift uses the `callAsFunction()` method to
simplify call site syntax, see
[Methods with Special Names](https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID622)
in *The Swift Programming Language*.

- Parameters
  - value: The value to present.
  - sharingBehavior: the sharing behavior for the opened window.

---

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)