I have a simple model class I want to use with SwiftData:
@Model
class Destination {
var name: String
var expenses: Double
init(name: String = "", expenses: Double = 0.0) {
self.name = name
self.expenses = expenses
}
}
I want to edit entries that are created, and for this I have created the following EditView, where I use @Bindable:
struct EditDestinationView: View {
@Bindable var destination: Destination
var body: some View {
Form {
TextField("Name", text: $destination.name)
TextField("Expenses", text: $destination.expenses)
}
}
.navigationTitle("Edit Destination")
.navigationBarTitleDisplayMode(.inline)
}
}
The problem I have is the double value "expenses", which I can't use in TextField.
Cannot convert value of type 'Binding<Double>' to expected argument type 'Binding<String>'
Question: What would be the best way to read/update destination.expenses with the value from the textField?
TextFieldinitializers withvalueandformat.