Per this thread, it appears there is a bug when using a binding from string to decimal with a text field, where the value does not get stored:
https://developer.apple.com/forums/thread/687521
TextField("creditHours", value: $course.creditHours, formatter: NumberFormatter())
// also occurs if you pass in your own formatter such as:
let formatter: NumberFormatter = {
let f = NumberFormatter()
f.numberStyle = .decimal
return f
}()
The “working” suggestion on the bottom of that thread is to listen to the onChange event and manually persist it.
@State var hours: String = ""
TextField("hours", text: $hours).onChange(of: hours) { val in
if let dec = Double(val) {
try! realm.write {
var c = course.thaw()!
c.creditHours = try! Decimal128(string: val)
}
}
}
However, the value still does not persist to the database.
Given Decimal128 is a realm swift class, I’m not sure how to diagnose further.