Search string in an <AnyObject> array with case insensitive
I have an application that stores string values from a server. Then I use SearchView to write a string that may be in the list. It must be case insensitive. While I have it. But this is not the magic I'm looking for.
if (myListTags as NSArray).containsObject(searchBar.text!) {
print("FOUND")
getCategoryPick()
}
I tried to join him with help caseInsensitiveCompare, but I failed. Any help for me? It would be great if this code could understand the similarity of letters in Czech .. (č = c, ž = z, í = i ......)
+4
2 answers
"č" "LATIN SMALL LETTER C WITH CARON". "c" + ", (" CARON ") " ".
(,
"č" = "c" ), .DiacriticInsensitiveSearch:
let list = ["č", "ž"]
let search = "C"
if (list.contains {
$0.compare(search, options: [.DiacriticInsensitiveSearch, .CaseInsensitiveSearch]) == .OrderedSame
}) {
print("Found")
}
, :
if (list.contains {
$0.rangeOfString(search, options: [.DiacriticInsensitiveSearch, .CaseInsensitiveSearch]) != nil
}) {
print("Found")
}
+7
localizedCaseInsensitiveCompare():
if myListTags.contains({(($0 as? NSString)?.localizedCaseInsensitiveCompare(searchBar.text!) ?? .OrderedAscending) == .OrderedSame }) {
}
+3