<!--
{
  "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/autosave(completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIDocument(im)autosaveWithCompletionHandler:"
  },
  "title" : "autosave(completionHandler:)"
}
-->

# autosave(completionHandler:)

Initiates automatic saving of documents with unsaved changes.

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

## Parameters

`completionHandler`

A block with code to execute after automatic saving concludes. The block returns no value and has one parameter:

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

    The block is invoked on the calling queue.

## Discussion

[`UIDocument`](/documentation/UIKit/UIDocument) periodically invokes this method to initiate a save operation if there are unsaved changes. You shouldn’t call this method directly. Subclasses can override it if they want to do special things with autosaving. The default implementation of this method invokes the [`hasUnsavedChanges`](/documentation/UIKit/UIDocument/hasUnsavedChanges) method and, if that returns <doc://com.apple.documentation/documentation/Swift/true>, it invokes the [`save(to:for:completionHandler:)`](/documentation/UIKit/UIDocument/save(to:for:completionHandler:)) method.

This method should only be invoked for period-based saves. You may invoke it with the `success` parameter of the completion-handler parameter set to <doc://com.apple.documentation/documentation/Swift/false> and return; this makes it safe to not actually save when [`autosave(completionHandler:)`](/documentation/UIKit/UIDocument/autosave(completionHandler:)) is invoked. However, if you call [`save(to:for:completionHandler:)`](/documentation/UIKit/UIDocument/save(to:for:completionHandler:)), saving of document data must occur.

---

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)