Convert from Fahrenheit to Celsius?

Hello Everyone,

In the example code, I'm trying to convert from Fahrenheit to Celsius, but I'm not succeeding. Output is always in Fahrenheit. My code is this:

  func formattedTemperature(_ temp: Measurement<UnitTemperature>) -> String {

        let tempC = temp.converted(to: .celsius)

        return tempC.formatted(.measurement(width: .abbreviated, usage: .weather))

    }

In the simulator I also went into the settings and switched in General->Language/Region from F to C. But this also had not effect.

Would anyone have an idea how to correct this?

Thanks and best regards, Patrick

Answered by Scott in 717084022

It’s a little surprising that usage: .weather isn’t respecting your locale settings, but if your goal anyway is to override the locale and always use ºC, then use usage: .asProvided.

Accepted Answer

It’s a little surprising that usage: .weather isn’t respecting your locale settings, but if your goal anyway is to override the locale and always use ºC, then use usage: .asProvided.

Convert from Fahrenheit to Celsius?
 
 
Q