Skip to content

Commit

Permalink
Respect the locale in the data source when sorting.
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Mar 1, 2020
1 parent 4655905 commit 1e61597
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CountryPickerView/CountryPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ extension CountryPickerViewController {
func prepareTableItems() {
if !showOnlyPreferredSection {
let countriesArray = countryPickerView.countries
let locale = dataSource.localeForCountryNameInList

var groupedData = Dictionary<String, [Country]>(grouping: countriesArray) {
let name = $0.localizedName(dataSource.localeForCountryNameInList) ?? $0.name
let name = $0.localizedName(locale) ?? $0.name
return String(name.capitalized[name.startIndex])
}
groupedData.forEach{ key, value in
groupedData[key] = value.sorted(by: { (lhs, rhs) -> Bool in
return lhs.localizedName() ?? lhs.name < rhs.localizedName() ?? rhs.name
return lhs.localizedName(locale) ?? lhs.name < rhs.localizedName(locale) ?? rhs.name
})
}

Expand Down

0 comments on commit 1e61597

Please sign in to comment.