Here is a demo project to illustrate the issue: https://github.com/yuri-qualtie/UseMetricSystemDemo
Precondition: Change user region to not US(for example Australia) in System Preferences -> Language and Region -> Region
We expect that code:
Code Block print(Locale.current.usesMetricSystem)
prints false when -AppleLocale en_US is set but actual result is true
Probably there is alternative way how to change measurement system via launch arguments or App's settings in Xcode?
Code Block -AppleLocale en_US -AppleMetricUnits <false/> -AppleMeasurementUnits Inches
There are two things to note here:
These preferences keys are not considered API. It’s fine to use them for tests and so on, but you should not ship code that relies on them. Rather, continue to use Locale APIs like usesMetricSystem.
Apropos usesMetricSystem, be aware that we no longer use a strict Boolean value here. The popup now shows three values (Metric, US, UK) reflected in NSLocaleMeasurementSystem. I believe NSMeasurementFormatter will do the right thing here, but it’s not something I’ve dug into in detail.
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Weirdly, if you’re testing this in a command-line tool (rather than app), you have to initialise the UserDefaults system before you get the locale. So this code:
Code Block _ = UserDefaults.standard let loc = Locale.current print(loc)
prints en_US but, if you drop the first line, it prints your current locale (en_GB in my case).