Contents

modelContext

Current model context Query interacts with.

Declaration

@MainActor @preconcurrency var modelContext: ModelContext { get }

Discussion

Access this value from Query property wrapper’s stored property:

struct RecipeList: View {
    @Query var recipes: [Recipe]
    var body: some View {
        ChangesIndicator(
            hasChanges: _recipes.modelContext.hasChanges)
    }
}

Only access this property within of a view’s body property, otherwise its value may be invalid.

See Also

Getting query configuration