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

# modelContext(_:)

Sets the model context in this scene’s environment.

## Declaration

```swift
@MainActor @preconcurrency func modelContext(_ modelContext: ModelContext) -> some Scene

```

## Parameters

- `modelContext`: The model context to set in this scene’s environment.

## Discussion

Discussion In this example, RecipesApp sets a shared model context to use for all of its windows: @Model class Recipe { ... }

@main struct RecipesApp: App {     var body: some Scene {         WindowGroup {             RecipesList()         }         .modelContext(myContext)     } } The environment’s modelContext property will be assigned a myContext. All implicit model context operations in this scene, such as Query properties, will use the environment’s context.

## See Also

### Configuring a data model

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