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

# rollback()

Discards pending inserts and deletes, restores changed models to their most recent committed state, and empties the undo stack.

## Declaration

```swift
func rollback()
```

## See Also

### Persisting unsaved changes

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