---
title: save()
framework: swiftdata
role: symbol
role_heading: Instance Method
path: swiftdata/modelcontext/save()
---

# save()

Writes any pending inserts, changes, and deletes to the persistent storage.

## Declaration

```swift
func save() throws
```

## Mentioned in

Preserving your app’s model data across launches

## Discussion

Discussion important: Use the hasChanges property to determine whether the context has uncommitted changes before invoking this method. Otherwise, SwiftData may perform unnecessary work.

## See Also

### Persisting unsaved changes

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