79676755

Date: 2025-06-23 21:03:33
Score: 1
Natty:
Report link

I don't know if this is good practice, but what I do is have my outer view with the query:

struct OuterView: View {
    @Query var data: [Item]
    var body: some View {
        MiddleView(date: data)
    }
}

Then Have a MiddleView which has a @State and calls a InnerView:

struct MiddleView: View {
    @State var data: [Item]
    var body: some View {
        InnerView(date: $data)
    }
}

And the InnerView is:

struct InnerView: View {
    @Binding var data: [Item]
    var body: some View {
        TextEditor(text: $date.name)
    }
}

This works because the SwiftData models are classes and are reference objects.

This is what I do, don't know if it is best practice, but this way you don't have to use the modelContext.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @State
  • Low reputation (1):
Posted by: Kitten Apps-Films