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

# beginSheet(with:modalFor:delegate:didEnd:contextInfo:)

Displays a Print panel sheet and runs it modally for the specified window.

```
func beginSheet(with printInfo: NSPrintInfo, modalFor docWindow: NSWindow, delegate: Any?, didEnd didEndSelector: Selector?, contextInfo: UnsafeMutableRawPointer?)
```

## Parameters

`printInfo`

The printing information for the current job.

`docWindow`

The window on which to display the sheet.

`delegate`

A modal delegate object assigned to handle the closing of the Print panel sheet.

`didEndSelector`

The selector to call on the modal delegate object when the sheet is dismissed. The signature of this method is listed in the Discussion section.

`contextInfo`

A pointer to context data the `didEndSelector` method needs to process the sheet. This data is user-defined and may be `NULL`.

## Discussion

When the modal session ends, if `modalDelegate` and `didEndSelector` contain non-`nil` values, the method specified by `didEndSelector` is invoked on the object in `modalDelegate`. The data you specify in `contextInfo` is passed as a parameter to the `didEndSelector` method. The object in `modalDelegate` is not the same as a delegate assigned to the panel. Modal delegates for sheets are temporary and the relationship lasts only until the sheet is dismissed.

The `didEndSelector` argument must have the following signature:

```objc
- (void)printPanelDidEnd:(NSPrintPanel *)printPanel returnCode:(NSInteger)returnCode  contextInfo: (void *)contextInfo;
```

The value passed as `returnCode` is either `NSCancelButton` or `NSOKButton`. The value `NSOKButton` is returned even if the user clicked the Preview button.

---

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)