---
title: DataStore
framework: swiftdata
role: symbol
role_heading: Protocol
path: swiftdata/datastore
---

# DataStore

An interface that enables SwiftData to read and write model data without knowledge of the underlying storage mechanism.

## Declaration

```swift
protocol DataStore : AnyObject
```

## Topics

### Creating a data store

- [init(_:migrationPlan:)](swiftdata/datastore/init(_:migrationplan:).md)

### Accessing store information

- [configuration](swiftdata/datastore/configuration-swift.property.md)
- [Configuration](swiftdata/datastore/configuration-swift.associatedtype.md)
- [DataStoreConfiguration](swiftdata/datastoreconfiguration.md)
- [identifier](swiftdata/datastore/identifier.md)
- [schema](swiftdata/datastore/schema.md)

### Processing fetch requests

- [fetch(_:)](swiftdata/datastore/fetch(_:).md)
- [DataStoreFetchRequest](swiftdata/datastorefetchrequest.md)
- [DataStoreFetchResult](swiftdata/datastorefetchresult.md)
- [Snapshot](swiftdata/datastore/snapshot.md)
- [DataStoreSnapshot](swiftdata/datastoresnapshot.md)
- [DataStoreSnapshotValue](swiftdata/datastoresnapshotvalue.md)
- [fetchCount(_:)](swiftdata/datastore/fetchcount(_:).md)
- [fetchIdentifiers(_:)](swiftdata/datastore/fetchidentifiers(_:).md)

### Persisting model data

- [save(_:)](swiftdata/datastore/save(_:).md)
- [DataStoreSaveChangesRequest](swiftdata/datastoresavechangesrequest.md)
- [DataStoreSaveChangesResult](swiftdata/datastoresavechangesresult.md)

### Removing all persisted model data

- [erase()](swiftdata/datastore/erase().md)

### Sharing cached data between model contexts

- [initializeState(for:)](swiftdata/datastore/initializestate(for:).md)
- [EditingState](swiftdata/editingstate.md)
- [cachedSnapshots(for:editingState:)](swiftdata/datastore/cachedsnapshots(for:editingstate:).md)
- [invalidateState(for:)](swiftdata/datastore/invalidatestate(for:).md)

## Relationships

### Inherited By

- [DataStoreBatching](swiftdata/datastorebatching.md)

### Conforming Types

- [DefaultStore](swiftdata/defaultstore.md)

## See Also

### Model storage

- [Maintaining a local copy of server data](swiftdata/maintaining-a-local-copy-of-server-data.md)
- [DefaultStore](swiftdata/defaultstore.md)
- [DataStoreBatching](swiftdata/datastorebatching.md)
- [HistoryProviding](swiftdata/historyproviding.md)
- [Building a document-based app using SwiftData](swiftui/building-a-document-based-app-using-swiftdata.md)
- [ModelDocument](swiftdata/modeldocument.md)
