<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Scene/modelContext(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI5SceneP01_a5Data_aB0E12modelContextyQr0aD005ModelF0CF"
  },
  "title" : "modelContext(_:)"
}
-->

# modelContext(_:)

Sets the model context in this scene’s environment.

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

## Parameters

`modelContext`

The model context to set in this scene’s environment.

## 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`](/documentation/SwiftUI/EnvironmentValues/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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)