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

# scheduleAutosaving()

Schedules periodic autosaving for the purpose of crash protection.

```
func scheduleAutosaving()
```

## Discussion

The default implementation of this method checks to see if autosaving is turned on and, if so and if `[self hasUnautosavedChanges]` returns <doc://com.apple.documentation/documentation/Swift/true>, schedules an `NSTimer` to invoke [`autosave(withDelegate:didAutosave:contextInfo:)`](/documentation/AppKit/NSDocument/autosave(withDelegate:didAutosave:contextInfo:)) in the future. If `[self hasUnautosavedChanges]` returns <doc://com.apple.documentation/documentation/Swift/false> it unschedules any previously scheduled timer. It takes care not to cause [`autosave(withDelegate:didAutosave:contextInfo:)`](/documentation/AppKit/NSDocument/autosave(withDelegate:didAutosave:contextInfo:)) to be invoked before a previous invocation caused by it has finished. The exact timings it uses are complicated and subject to change in future releases of macOS. You can override this method to control when exactly periodic autosaving happens. It is invoked by [`updateChangeCount(_:)`](/documentation/AppKit/NSDocument/updateChangeCount(_:)) and [`updateChangeCount(withToken:for:)`](/documentation/AppKit/NSDocument/updateChangeCount(withToken:for:)).

---

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)