1

I'm doing something, which I've done many times. In the delegate method of UITextField textField.shouldChangeText(in: Range, replacementText: String), and even though my txtFieldAmount.keyboardType = .decimalPad I'm checking, if the value of textField can be converted into Float, because I use this type in other functions.

Since iOS 11, the decimal point in the keyboard is replaced with "," which causes the initialization of the Float value to be nil.

Example:

let value = "3.14" 
let float = Float(value) //procuces 3.14
let value2 = "3,14"
let float2 = Float(value2) //produces nil

It is a simple currency exchange application in which, I take the value from one textField and set a calculated value in second textField, in format "x.xx"

Any suggestions?

P.Todorov
  • 43
  • 10
  • 1
    This was always the case, this is locale specific. Use `NumberFormatter` to parse the number or just replace the `decimalSeparator` from current locale with `.`. This is definitely not new. Please, let users enter numbers in their own language, don't force English number formatting on every user. – Sulthan Oct 07 '17 at 11:43
  • @Sulthan can't say it has been always, because I'm running the app on iPhone 5 with iOS 10.3 and iPhone 7 with iOS 11.0.2 and they're behaving differently – P.Todorov Oct 07 '17 at 11:48
  • And what is the locale (region settings) set on those devices? – Sulthan Oct 07 '17 at 11:50
  • @Sulthan both are set to region: Bulgaria – P.Todorov Oct 07 '17 at 11:53

0 Answers0