<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIDocument/close(completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIDocument(im)closeWithCompletionHandler:"
  },
  "title" : "close(completionHandler:)"
}
-->

# close(completionHandler:)

Asynchronously closes the document after saving any changes.

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

## Parameters

`completionHandler`

A block with code to execute after the save-and-close operation concludes. The block returns no value and has one parameter:

- `success`: <doc://com.apple.documentation/documentation/Swift/true> if any save operation succeeds, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

    The block is invoked on the main queue.

## 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`](/documentation/UIKit/UIDocument/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 <doc://com.apple.documentation/documentation/Swift/false>), you can respond in an appropriate manner.

You typically wouldn’t override this method. The default implementation calls the [`autosave(completionHandler:)`](/documentation/UIKit/UIDocument/autosave(completionHandler:)) method.

---

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)