Search code examples
swiftuisearchbaruppercaselowercase

How to fix searchBar, not sensitive to uppercase or lowercase?


When I search in my searchBar using mix of uppercase and lowercase, it doesnt work.

this is my code to filter the search bar

filterednames = nameList.filter{(($0.value as! [String:Any])["name"] as! String).contains(searchText)}

I want to be able to search for the names even if its a mix of uppercase and lowercase


Solution

  • filterednames = nameList.filter{(($0.value as! [String:Any])["name"] as! String).range(of: searchText, options: .caseInsensitive) != nil}
    

    adding .range(of: searchText, options: .caseInsensitive) != nil will make it case insensitive