---
title: "close(completionHandler:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uidocument/close(completionhandler:)"
---

# close(completionHandler:)

Asynchronously closes the document after saving any changes.

## Declaration

```swift
func close(completionHandler: (@Sendable (Bool) -> Void)? = nil)
```

```swift
func close() async -> Bool
```

## Parameters

- `completionHandler`: A block with code to execute after the save-and-close operation concludes. The block returns no value and has one parameter: The block is invoked on the main queue.

## Discussion

Discussion You call this method to begin the sequence of method calls that saves a document safely and asynchronously. The file-system location of the document derives from the fileURL property. After the save operation concludes, the code in completionHandler is executed. In this code, you can close the document — for example, by removing the document’s view from the screen. Additionally, if the save operation didn’t succeed (success is false), you can respond in an appropriate manner. You typically wouldn’t override this method. The default implementation calls the autosave(completionHandler:) method.

## See Also

### Writing document data

- [contents(forType:)](uikit/uidocument/contents(fortype:).md)
- [save(to:for:completionHandler:)](uikit/uidocument/save(to:for:completionhandler:).md)
- [writeContents(_:andAttributes:safelyTo:for:)](uikit/uidocument/writecontents(_:andattributes:safelyto:for:).md)
- [writeContents(_:to:for:originalContentsURL:)](uikit/uidocument/writecontents(_:to:for:originalcontentsurl:).md)
- [savingFileType](uikit/uidocument/savingfiletype.md)
- [fileAttributesToWrite(to:for:)](uikit/uidocument/fileattributestowrite(to:for:).md)
- [fileNameExtension(forType:saveOperation:)](uikit/uidocument/filenameextension(fortype:saveoperation:).md)
