Skip to content

Commit

Permalink
slightly improve search of appropriate locale for currency formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Sega-Zero committed Nov 24, 2019
1 parent d48acef commit 6d23cfb
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions iso4217/Classes/CurrencyCode+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ private extension CurrencyCode {
}

var locale: Locale {
for localeId in Locale.availableIdentifiers {
let locale = Locale(identifier: localeId)
if let code = locale.currencyCode, code == self.rawValue {
return locale
}
let appropriateLocales: [Locale] = Locale.availableIdentifiers.compactMap {
let locale = Locale(identifier: $0)
guard let code = locale.currencyCode, code == self.rawValue else { return nil }
return locale
}

return self.canonicalLocale
return appropriateLocales.first(where: { $0.currencySymbol != $0.currencyCode }) ?? appropriateLocales.first ?? self.canonicalLocale
}

var priceLocale: Locale {
Expand Down

0 comments on commit 6d23cfb

Please sign in to comment.