SwifttData Record Update

Hi

When connecting a SwiftData module property to a SwiftUI view such as a text field and the field changes by user the property get updated in the SwiftData database, now suppose I want to run a validation code or delay updates to Database till use click a submit button how to do that ? delay those auto updates if we can name it ?

Kind Regards

Code Example

import SwiftUI
import SwiftData
struct GListSel2: View {
@Bindable var patient: Patient
var body: some View {
HStack {
TextField("Gender", text: $patient.gender)
}
}
}
Answered by joadan in 812727022

ModelContext has a property autosaveEnabled that you can set to false and then handle validation and save logic in a button action or something

Accepted Answer

ModelContext has a property autosaveEnabled that you can set to false and then handle validation and save logic in a button action or something

SwifttData Record Update
 
 
Q