<!--
{
  "availability" : [
    "macOS: 10.0.0 - 10.10.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSApplication/beginSheet(_:modalFor:modalDelegate:didEnd:contextInfo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSApplication(im)beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:"
  },
  "title" : "beginSheet(_:modalFor:modalDelegate:didEnd:contextInfo:)"
}
-->

# beginSheet(_:modalFor:modalDelegate:didEnd:contextInfo:)

Starts a document modal session.

```
func beginSheet(_ sheet: NSWindow, modalFor docWindow: NSWindow, modalDelegate: Any?, didEnd didEndSelector: Selector?, contextInfo: UnsafeMutableRawPointer!)
```

## Parameters

`sheet`

The window object representing the sheet you want to display.

`docWindow`

The window object to which you want to attach the sheet.

`modalDelegate`

The delegate object that defines your `didEndSelector` method. If `nil`, the method in `didEndSelector` is not called.

`didEndSelector`

An optional method to call when the sheet’s modal session has ended. This method must be defined on the object in the `modalDelegate` parameter and have the following signature:

```objc
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
```

`contextInfo`

A pointer to the context info you want passed to the `didEndSelector` method when the sheet’s modal session ends.

## Discussion

This method displays the sheet modally on the specified window and returns control to the caller. Most events targeted at `docWindow` are prohibited while the sheet is displayed but the app’s main run loop runs normally otherwise.

---

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)