After upgrading to iOS 17 I am struggling to get decimals working in my app - here is a sample code: for clarity I provide a complete "working" sample (I am pulling data from a back-end server using json, etc - all of that is working ok, it's the UI issue - see below):
Model
import Foundation
struct TestFloat: Encodable {
var testFloatNumber: Float = 0
}
Observable Class
import Foundation
class TestFloatViewModel: ObservableObject {
@Published var testFloat = TestFloat()
}
View
struct TestFloatView: View {
@ObservedObject var testFloatVM: TestFloatViewModel
let formatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
return formatter
}()
var body: some View {
VStack {
HStack {
Text("Enter Float Number")
Spacer()
}
Spacer()
.frame(height: 2.0)
HStack {
TextField("Enter Float Number", value: $testFloatVM.testFloat.testFloatNumber, formatter: formatter)
.keyboardType(.decimalPad)
.textFieldStyle(.roundedBorder)
}
}
}
}
This is working on a device with iOS16; however when run on device with iOS17:
- you can enter maximum four digits?
- using backspace you can delete all numbers apart of the first one
- you cannot enter the decimal (.) at all even though decimal keyboard is provided
Any help is greatly appreciated.