skip to Main Content

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?

2

Answers


  1. 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!

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search