I have a class that holds the data coming from my api
class Shops {
private var _familiy_id: String?
private var _logo : String?
private var _shopname : String?
var familiy_id : String{
return _familiy_id!
}
var shopname : String{
return _shopname!
}
var Logo : String{
return _logo!
}
init(shopname : String , Logo : String , family_id : String) {
self._shopname = shopname
self._logo = Logo
self._familiy_id = family_id
}
}
I'm trying to filter the name of the shops and splay it if users edit the search bar. SO I tried this code :
var searchActive : Bool = false
var filtered:[Shops] = []
var shops = [Shops]()
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
filtered = searchText.isEmpty ? shops : shops.filter { (item: String) -> Bool in
// If dataItem matches the searchText, return true to include it
return item.range(of: searchText, options: .caseInsensitive, range: nil, locale: nil) != nil
}
tableView.reloadData()
}
but I get an error saying that item has no member range! Sorry this is my first time to implement UISearchBar in my project so I'm trying to learn from other code