<!--
{
  "availability" : [
    "macOS: 10.9.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWindow/endSheet(_:returnCode:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSWindow(im)endSheet:returnCode:"
  },
  "title" : "endSheet(_:returnCode:)"
}
-->

# endSheet(_:returnCode:)

Ends a document-modal session and dismisses the specified sheet.

```
func endSheet(_ sheetWindow: NSWindow, returnCode: NSApplication.ModalResponse)
```

## Parameters

`sheetWindow`

The window object that represents the sheet to dismiss.

`returnCode`

The return code to send to the completion handler. You can use  a custom value that you define or one of the return codes defined in the [`NSApplication.ModalResponse`](/documentation/AppKit/NSApplication/ModalResponse) enumeration or  `Additional NSModalResponse Values`.

## Discussion

This method ends the modal session with the specified return code.

---

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)