Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No data when countries in Arabic language #4

Closed
Dev-Khaled opened this issue Sep 21, 2018 · 7 comments
Closed

No data when countries in Arabic language #4

Dev-Khaled opened this issue Sep 21, 2018 · 7 comments
Assignees
Labels

Comments

@Dev-Khaled
Copy link

Dev-Khaled commented Sep 21, 2018

No data when countries in Arabic language

// This code is wrong
    func fetchSectionCountries() {
        for section in sections {
            let sectionCountries = countries.filter({ (country) -> Bool in
                return country.countryName.first! == section
            })
            sectionCoutries[section] = sectionCountries
        }
    }

@SURYAKANTSHARMA
Copy link
Owner

Hi @dev thanks for reporting the issue, I think this issue is not in my knowledge I had tested the code and many applications used it, although I couldn't help today but surely look into this Asap. Please share the details so that I can help you smoothly.

@Dev-Khaled
Copy link
Author

Solution

    func fetchSectionCountries() {
        sections = countries.map({ String($0.countryName.prefix(1)).first! }).unique

        for section in sections {
            let sectionCountries = countries.filter({ (country) -> Bool in
                return country.countryName.first! == section
            })
            sectionCoutries[section] = sectionCountries
        }
    }

extension Array where Element : Equatable {
    var unique: [Element] {
        var uniqueValues: [Element] = []
        forEach { item in
            if !uniqueValues.contains(item) {
                uniqueValues += [item]
            }
        }
        return uniqueValues
    }
}

@SURYAKANTSHARMA SURYAKANTSHARMA self-assigned this Sep 22, 2018
@SURYAKANTSHARMA
Copy link
Owner

Nice to know you had solve the problem 🥇 could you please explain a bit how it solve the problem? So that i update my repo accordingly. it is seems like is Duplicacy is the problem (Not clear for me how) ? is it please let me know.

@Dev-Khaled
Copy link
Author

You get country names from the system, and it depends on device language.

for non English languages, constant "sections" with English letters will be wrong, so I just initiated sections with first letter from each language name,

countries.map({ String($0.countryName.prefix(1)).first! })
then filtered the duplicates.

.unique
Best

@SURYAKANTSHARMA
Copy link
Owner

ok @Dev-Khaled thanks for clearification.

@SURYAKANTSHARMA
Copy link
Owner

@Dev-Khaled Awesome bro 👍 Good Catch 💯 . #4 Done in version 1.1.6.

@VRWayVl
Copy link

VRWayVl commented Nov 8, 2018

the same issue with russian language

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants