@State private var entryPrice: Double?
TextField("0", value: $entryPrice, format: .currency(code: "USD")) // DOES NOT WORK
TextField("0", value: $entryPrice, format: .currency(code: "EUR")) // WORKS
When observing the value:
TextField("0", value: Binding(get: {
entryPrice
}, set: { newValue in
print(newValue)
entryPrice = newValue
}), format: .currency(code: "USD"))
I notice while you are entering decimal numbers the entry price gets updated. But whenever the focus leaves the textfield on USD or other locale than EUR it retrieves nil as the newValue and the TextField becomes empty. It is really frustrating, because I don't know why this happens.
xCode 14.1 Beta 2 iOS 16.0
Found a Workaround
TextField("0", value: $entryPrice, format: .currency(code:"USD").locale(Locale(identifier: "en_US")))