<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "swift: 5.9.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftData",
  "identifier" : "/documentation/SwiftData/ModelContext/autosaveEnabled",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "SwiftData"
    ],
    "preciseIdentifier" : "s:9SwiftData12ModelContextC15autosaveEnabledSbvp"
  },
  "title" : "autosaveEnabled"
}
-->

# autosaveEnabled

A Boolean value that indicates whether the context should automatically save
any pending changes when certain events occur.

```
var autosaveEnabled: Bool { get set }
```

## Discussion

When `true`, the context calls [`save()`](/documentation/SwiftData/ModelContext/save()) after you make changes to any
inserted or registered models. The context also calls `save()` at various
times during the lifecycle of windows, scenes, views, and sheets.

The default value is `false`. SwiftData automatically sets this property to
`true` for the model container’s [`mainContext`](/documentation/SwiftData/ModelContainer/mainContext).

---

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)