I have the following SwiftData model:
import SwiftData
import Foundation
@Model
final class CollectionModel {
@Attribute(.unique)
var name: String = ""
}
And in my view I declare it as a @Bindable
, in this way:
@Bindable var collectionStore: CollectionModel = CollectionModel()
And then in my View I create my form like this:
Form {
Text("Add Collection")
TextField("Name", text: $collectionStore.name)
Button("Save", action: self.saveCollection)
}.alert(self.formAlertMessage, isPresented: self.$formShowAlert, actions: {
Button(LocalizedStringKey("Ok"), role: .cancel) {}
})
But when I save the form, the variables are empty. I have checked that via debugger.
6