NumberFormatter not correctly identifying Locale currency settings in iOS 17 beta with Xcode 15.0 beta

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("$")
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?

Accepted Reply

Answer Found:

TL;DR

iOS 17 simulator sets the region in Language & Region settings to world by default. Previous iOS version simulators set it to your current location.

Full Answer

If you 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 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. 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.

Replies

Answer Found:

TL;DR

iOS 17 simulator sets the region in Language & Region settings to world by default. Previous iOS version simulators set it to your current location.

Full Answer

If you 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 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. 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.

How would you go around changing the region in an Xcode preview? I can't figure out a way.