---
title: "endSheet(_:returnCode:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nswindow/endsheet(_:returncode:)"
---

# endSheet(_:returnCode:)

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

## Declaration

```swift
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 doc://com.apple.appkit/documentation/AppKit/NSApplication/ModalResponse enumeration or Additional NSModalResponse Values.

## Discussion

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

## See Also

### Managing Sheets

- [attachedSheet](appkit/nswindow/attachedsheet.md)
- [isSheet](appkit/nswindow/issheet.md)
- [beginSheet(_:completionHandler:)](appkit/nswindow/beginsheet(_:completionhandler:).md)
- [beginCriticalSheet(_:completionHandler:)](appkit/nswindow/begincriticalsheet(_:completionhandler:).md)
- [endSheet(_:)](appkit/nswindow/endsheet(_:)-4dmmq.md)
- [sheetParent](appkit/nswindow/sheetparent.md)
- [sheets](appkit/nswindow/sheets.md)
