---
title: "modelContainer(_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/scene/modelcontainer(_:)"
---

# modelContainer(_:)

Sets the model container and associated model context in this scene’s environment.

## Declaration

```swift
@MainActor @preconcurrency func modelContainer(_ container: ModelContainer) -> some Scene

```

## Parameters

- `container`: The model container to use for this scene.

## Discussion

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.

## See Also

### Configuring a data model

- [modelContext(_:)](swiftui/scene/modelcontext(_:).md)
- [modelContainer(for:inMemory:isAutosaveEnabled:isUndoEnabled:onSetup:)](swiftui/scene/modelcontainer(for:inmemory:isautosaveenabled:isundoenabled:onsetup:).md)
