<!--
{
  "availability" : [
    "macOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWindow/beginSheet(content:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "s:So8NSWindowC7SwiftUIE10beginSheet7content17completionHandlerAbCE07HostingE14RepresentationCy_xGxyXE_yycSgtAC4ViewRzlF"
  },
  "title" : "beginSheet(content:completionHandler:)"
}
-->

# beginSheet(content:completionHandler:)

Presents a SwiftUI view as a sheet on the receiving NSWindow.

```
@discardableResult @MainActor @preconcurrency func beginSheet<V>(@ContentBuilder content: () -> V, completionHandler: (() -> Void)? = nil) -> NSWindow.HostingSheetRepresentation<V> where V : View
```

## Parameters

`content`

The SwiftUI view to present in a sheet.

`completionHandler`

An optional completion handler that is called
when the sheet is dismissed for any reason.

## Return Value

A discardable [`NSWindow.HostingSheetRepresentation`](/documentation/AppKit/NSWindow/HostingSheetRepresentation)
instance.

## Discussion

The presented view supports the same features as when used in the
<doc://com.apple.documentation/documentation/SwiftUI/View/sheet(isPresented:onDismiss:content:)>
or <doc://com.apple.documentation/documentation/SwiftUI/View/sheet(item:onDismiss:content:)>
view modifier, such as:

- Automatic dismissal with the Escape key and disabling interactive
  dismissal with <doc://com.apple.documentation/documentation/SwiftUI/View/interactiveDismissDisabled(_:)>
- Use of [`@Environment(\.dismiss)`](doc://com.apple.documentation/documentation/SwiftUI/EnvironmentValues/dismiss)
  to dismiss the sheet
- Sheet sizing using <doc://com.apple.documentation/documentation/SwiftUI/View/presentationSizing(_:)>
- Standard sheet toolbars using <doc://com.apple.documentation/documentation/SwiftUI/View/toolbar(content:)>.

```
parentWindow.beginSheet {
    NameADogSheet(dog: observableDog)
}

struct NameADogSheet: View {
    var dog: Dog
    @Environment(\.dismiss) private var dismiss
    @State private var name: String = ""

    var body: some View {
        Form {
            TextField("Who's a good dog?", text: $name)
        }
        .formStyle(.grouped)
        .toolbar {
            ToolbarItem(placement: .cancellationAction) {
                Button("Cancel") {
                    dismiss()
                }
            }
            ToolbarItem(placement: .confirmationAction) {
                Button("Suggest Name") {
                    dog.name = name
                    dismiss()
                }
                .disabled(name.isEmpty)
            }
        }
    }
}
```

The returned [`NSWindow.HostingSheetRepresentation`](/documentation/AppKit/NSWindow/HostingSheetRepresentation) can be ignored
unless the sheet needs to be manipulated from an AppKit context, such as
changing the root view or programmatically changing the sheet.

---

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)