modelContainer(_:)
Sets the model container and associated model context in this scene’s environment.
Declaration
@MainActor @preconcurrency func modelContainer(_ container: ModelContainer) -> some Scene
Parameters
- container:
The model container to use for this scene.
Discussion
In this example, RecipesApp sets a shared model container to use for all of its windows:
@main
struct RecipesApp: App {
@State private var container = ModelContainer(...)
var body: some Scene {
WindowGroup {
RecipesList()
}
.modelContainer(container)
}
}The environment’s modelContext property will be assigned a new context associated with this container. All implicit model context operations in this scene, such as Query properties, will use the environment’s context.