Created
January 26, 2023 19:49
-
-
Save BasThomas/f91bf58c7015c2295b47130a1a7a7bcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Locale { | |
var defaultTemperatureUnit: UnitTemperature { | |
if #available(iOS 16, *) { | |
return UnitTemperature(forLocale: self, usage: .general) | |
} else { | |
let mCel = Measurement(value: 0, unit: UnitTemperature.celsius) | |
let f = MeasurementFormatter() | |
f.locale = self | |
let s1 = f.string(from: mCel) | |
f.unitOptions = .providedUnit | |
let s2 = f.string(from: mCel) | |
return s1 == s2 ? .celsius : .fahrenheit | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment