2

I'm currently developing an application for iOS and I recently updated to the iOS 17 beta along with Xcode 15.0 beta. I am trying to use NumberFormatter to format a Double to a currency string (in my case, American Dollars $). Here is the snippet of my code:

let formatter = NumberFormatter()
formatter.currencySymbol = Locale.current.currencySymbol
print(Locale.current.currency)
print(Locale.current.currencySymbol)
print(Locale.current.currency?.identifier)
print(Locale.current)
formatter.numberStyle = .currency

When running this on iOS 16, I get the following output:

Optional(Foundation.Locale.Currency(_identifier: "USD", _normalizedIdentifier: "usd"))
Optional("$")
Optional("USD")
en_US (current)

However, when running the same code on iOS 17 beta, the output is different:

nil
Optional("¤")
nil
en_001 (fixed)

It appears that the Locale's currency and identifier properties are returning nil, and the Locale itself is being identified differently.

Has anyone else encountered this issue with iOS 17 beta and Xcode 15.0 beta? Is this a bug in the beta versions, or have there been changes in the way Locale should be used for currency formatting?

NSSpeedForce
  • 127
  • 9

2 Answers2

3

I too have run into this, but the fix is simple: Launch the simulator's Settings app and navigate to General > "Language & Region". You'll note that Region is set to "world" by default and I'm assuming that results in the en_001 language code. Change Region to whatever locale you want to work with and you should be getting a more specific ISO code.

I'm not sure if this is a change in iOS 17, or something just with the simulator beta or what, but it's probably worth noting that "world" may be a legit region in the near future.

Good luck!

sherb
  • 5,845
  • 5
  • 35
  • 45
  • That solved the problem. I restored both iOS 16 and 17 simulators and checked their Language & Region settings to see if the discrepancy was related to the simulator or the iOS version. iOS 16 was set to my location by default. iOS 17 was set to world as you mentioned. I changed iOS 17 simulator to my location and the issue was resolved. My guess is it is some privacy update for iOS 17. Perhaps we will learn more later. – NSSpeedForce Jun 08 '23 at 01:41
0

I noticed something similar with Xcode 15 building a macOS app... It seems to be using some weird Locale en_001, which had some unintended side effects like setting Calendar.current.firstWeekday to 2 instead of 1 like it should be with a Gregorian calendar.

I think this is a bug in Xcode.

lepolt
  • 501
  • 5
  • 13