@@ -143,7 +143,7 @@ open class EnergyFormatter: Formatter {
143143 //Convert to the locale-appropriate unit
144144 let unitFromJoules : Unit
145145
146- if numberFormatter . locale . usesCalories {
146+ if self . usesCalories {
147147 if numberInJoules > 0 && numberInJoules <= 4184 {
148148 unitFromJoules = . calorie
149149 } else {
@@ -177,25 +177,13 @@ open class EnergyFormatter: Formatter {
177177 /// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative
178178 /// - Note: Since this API is under consideration it may be either removed or revised in the near future
179179 open override func objectValue( _ string: String ) throws -> Any ? { return nil }
180- }
181-
182- /// TODO: Replace calls to the below function to use Locale.regionCode
183- /// Temporary workaround due to unpopulated Locale attributes
184- /// See https://bugs.swift.org/browse/SR-3202
185- extension Locale {
186- public var usesCalories : Bool {
187-
188- switch self . identifier {
189- case " en_US " : return true
190- case " en_US_POSIX " : return true
191- case " haw_US " : return true
192- case " es_US " : return true
193- case " chr_US " : return true
194- case " en_GB " : return true
195- case " kw_GB " : return true
196- case " cy_GB " : return true
197- case " gv_GB " : return true
198- default : return false
199- }
180+
181+ /// Regions that use calories
182+ private static let caloriesRegions : Set < String > = [ " en_US " , " en_US_POSIX " , " haw_US " , " es_US " , " chr_US " , " en_GB " , " kw_GB " , " cy_GB " , " gv_GB " ]
183+
184+ /// Whether the region uses calories
185+ private var usesCalories : Bool {
186+ return EnergyFormatter . caloriesRegions. contains ( numberFormatter. locale. identifier)
200187 }
188+
201189}
0 commit comments