I haven't tried this out but I think it should work something like that:
Create in your parent view the new context.
let container = try! ModelContainer(for: Model.self,
ModelConfiguration(inMemory: true)) // or whatever works for you
let localContext = ModelContext(container)
Then attach the localContext to a child view.
yourView
.modelContext(localContext)
In the child view you should have access to it via the environment.
@Environment(\.modelContext) var modelContext
If you want to use the same container like your original context, try originalContext.container and use that in step 1.
@Query in the child view will work on the given model context.
At least this is my theory. I don’t have time to check it, but maybe it helps you anyways.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: