---
title: autosaveEnabled
framework: swiftdata
role: symbol
role_heading: Instance Property
path: swiftdata/modelcontext/autosaveenabled
---

# autosaveEnabled

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

## Declaration

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

## Mentioned in

Preserving your app’s model data across launches

## Discussion

Discussion When true, the context calls 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.

## See Also

### Persisting unsaved changes

- [save()](swiftdata/modelcontext/save().md)
- [transaction(block:)](swiftdata/modelcontext/transaction(block:).md)
- [rollback()](swiftdata/modelcontext/rollback().md)
