Core Data, bindings, and save()

I am beginning work on my first SwiftUI application, which uses CoreData as its data-store. And I have an issue I'm having trouble wrapping my head around.


If I use an @ObservedObject property wrapper on a CoreData record, then use $property to bind an attribute in the record to a UI element, I understand that this sets up a two-way binding, which is good.


BUT, in the case of a non-modal view, what strategies are recommended for knowing when to save context?


Let me demonstrate my ignorance. This example is based on what I think I know (which is likely completely wrong):

@ObservedObject var obj: MyCoreDataObject
var body : some View {
     Toggle(isOn: obj.$active) {
          Text("Is it active?")
     }
}

Because of the binding ($active), the value of the toggle and the attribute in Core Data object ought to be synchronized. But if the user actually taps the toggle, thus causing the obj.active attribute to change, that change needs to be saved.


So, what are some ways to make sure that happens? Or have I missed the point?


Rick

Core Data, bindings, and save()
 
 
Q