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

# modelContext(_:)

Sets the model context in this view’s environment.

## Declaration

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

```

## Parameters

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

## Discussion

Discussion In this example, the RecipesList view sets a model context to use for all of its content: @Model class Recipe { ... } ... RecipesList()     .modelContext(myContext) The environment’s modelContext property will be assigned myContext. All implicit model context operations in this view, such as Query properties, will use the environment’s context.

## See Also

### Configuring a model

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