I've encountered a potential bug where a TextField connected to an optional value (not a string) works as expected when bound to a @State
property, but won't update a @Binding
property.
Here is some example code
import SwiftUI
struct ContentView: View
{
@Binding var boundValue: Double?
@State private var stateValue: Double? = 55
var body: some View
{
TextField("Bound value", value: $boundValue, format: .number)
Text("\(boundValue ?? .nan)")
TextField("State value", value: $stateValue, format: .number)
Text("\(stateValue ?? .nan)")
}
}
#Preview
{
ContentView(boundValue: .constant(42.00))
}
It's as though the optional value stored externally is preventing the value updating. Can anyone confirm whether this is intentional, or a bug?
This is in Xcode 26b6, on macOS Tahoe 26b8, but from this query it looks like the problem has existed for years.