One Logo Pool Ball
SwiftData · IOS API REFERENCE

ModelContainer

class · iOS 17.0+ · SDK 27.1

class ModelContainer

An object that manages an app's schema and model storage configuration.

Members (10)

method · iOS 17.0+ · Deprecated in iOS 100000.0

deleteAllData

TypeScript
deleteAllData(): void
Swift declaration
func deleteAllData()
get · iOS 17.0+

mainContext

TypeScript
get mainContext(): Promise<ModelContext>
Swift declaration
@MainActor var mainContext: ModelContext { get }
get · iOS 17.0+

configurations

TypeScript
get configurations(): Array<ModelConfiguration>
Swift declaration
var configurations: Set<ModelConfiguration> { get set }
set · iOS 17.0+

configurations

TypeScript
set configurations(value: Array<ModelConfiguration>)
Swift declaration
var configurations: Set<ModelConfiguration> { get set }
method · iOS 27.0+

storeIdentifier

TypeScript
storeIdentifier(name: string): (string) | null
Swift declaration
func storeIdentifier(forConfigurationNamed name: String) -> String?

Returns the on-disk store identifier for the given configuration name. Store identifiers are stable strings derived from the backing file path or the store's own initialization — they are *not* the configuration name. Use this function when you have the name you passed to `ModelConfiguration` and need the corresponding identifier to filter a `HistoryDescriptor`, interpret `PersistentIdentifier.storeIdentifier`, or route to a specific store. If no `ModelConfiguration` was given an explicit name at initialization time, the default name is `"default"`. - Parameter name: The `name` value from the `ModelConfiguration` used to create the store. - Returns: The store identifier string, or `nil` if no store is associated with `name` or if `invalidate()` has been called on this container.

method · iOS 27.0+

configurationName

TypeScript
configurationName(identifier: string): (string) | null
Swift declaration
func configurationName(forStoreIdentifier identifier: String) -> String?

Returns the configuration name associated with the given on-disk store identifier. Use this when you already have a store identifier — such as `PersistentIdentifier.storeIdentifier` from a fetched object or a store identifier from a history transaction — and need to map it back to the human-readable configuration name that produced that store. - Parameter identifier: A store identifier string, for example from `PersistentIdentifier.storeIdentifier` or a history transaction's store identifier. - Returns: The `name` of the `ModelConfiguration` that backs the given store, or `nil` if no store with that identifier exists in this container or if `invalidate()` has been called.

init · iOS 17.0+

init

TypeScript
static initForConfigurations(givenSchema: Schema, configurations: Array<ModelConfiguration>): ModelContainer
Swift declaration
init(for givenSchema: Schema, migrationPlan: (any SchemaMigrationPlan.Type)? = nil, configurations: [ModelConfiguration]) throws
init · iOS 18.0+

init

TypeScript
static initForConfigurations77162(givenSchema: Schema, configurations: Array<SDKHandle>): ModelContainer
Swift declaration
init(for givenSchema: Schema, configurations: [any DataStoreConfiguration]) throws
method · iOS 18.0+

erase

TypeScript
erase(): void
Swift declaration
func erase() throws
get · iOS 17.0+

schema

TypeScript
get schema(): Schema
Swift declaration
final let schema: Schema

Skipped declarations

4 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

ModelContainer.migrationPlan

Passing a Swift type itself is not supported.

ModelContainer.init(for:migrationPlan:configurations:)

Passing a Swift type itself is not supported.

ModelContainer.init(for:migrationPlan:configurations:)

A variable number of Swift arguments is not supported.

ModelContainer.init(for:configurations:)

Passing a Swift type itself is not supported.

All SwiftData types →