0

I am trying to show the temperature from weatherkit in a text field. If I use 'temp.formatted(.measurement(width: .abbreviated, usage: .weather)' for -0.31C it shows a weird value of -33F. It works for positive celsius values, only the negative ones have this issue.

Is there anything obvious I am doing wrong in the code shown? I am just starting to do some learning project with swiftUI.

let temp = Measurement(value: -0.31, unit: UnitTemperature.celsius)
print(temp)
print("Current default locale: \(Locale.current)")
print("\(temp.formatted(.measurement(width: .abbreviated, usage: .weather)))")
print(MeasurementFormatter().string(from: temp)) //this works
Output:
-0.31 °C
Current default locale: en_US (current)
-33°F
31.442°F
Sekar
  • 31
  • 4
  • Hmmm... I get this output: `-0.31 °C / Current default locale: en_US (current) / 31°F / 31.442°F` – DonMag Apr 10 '23 at 20:13
  • Same here. It works fine for me. I'm testing with a command-line app with Xcode 14.3. What version of Xcode and OS-version are you testing this on. I can't reproduce it. (Also `en_US (current)`) – Rob Napier Apr 11 '23 at 02:59
  • Using XCode 14.0 and MacOS Ventura 13.0.1 If I try it on the 'playgrounds app' from the appstore, it works fine. But get the incorrect result inside XCode playgrounds or XCode app – Sekar Apr 11 '23 at 21:10

0 Answers0