Re: NSMeasurementFormatter reversed

Gerriet M. Denkmann

On 26 Sep 2018, at 22:29, James Walker <> wrote:

On Sep 25, 2018, at 7:05 PM, Gerriet M. Denkmann <> wrote:

NSMeasurementFormatter is a magical tool which converts all stuff just into the right form the user wants to see.

But what about the other way round?

I have a TextField labeled “Desired Temperature” the user enters “83.4” - what does the user want?
Boiling hot (using Celsius) or comfortably warm (Fahrenheit)?

defaults find Temperature

at the command line produces

Found 1 keys in domain 'Apple Global Domain': {
AppleTemperatureUnit = Fahrenheit;
Excellent find! Thanks a lot!

There seem to be 3 ways to get this info:

NSString *temp1 = [NSUserDefaults.standardUserDefaults stringForKey: @"AppleTemperatureUnit"];

NSString *temp2 = [ NSLocale.currentLocale objectForKey: @"kCFLocaleTemperatureUnitKey"];

FOUNDATION_EXPORT NSLocaleKey const NSLocaleTemperatureUnit;
NSString *temp3 = [ NSLocale.currentLocale objectForKey: NSLocaleTemperatureUnit];

Probably the first one (the one you found) is the best, i.e. most likely to work in future OS versions.

All work on macOS and iOS.
The first one returns nil in the Simulator


Join to automatically receive all group messages.