Hamada Raouf
Hamada Raouf

Reputation: 105

Use UISearchBar with Firebase Database

I am trying to use UISearchBar with Firebase but I get an error when I try to type any right word

thank you

Upvotes: 1

Views: 121

Answers (2)

Hamada Raouf
Hamada Raouf

Reputation: 105

Thank You guys my problem it's was in the Number Of Rows In Section Function it's haven't return for filterHotels I edit my question if someone need the code also i'll edit it in github

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) ->  Int { if isSearching{ return filterHotels.count } else { return hotelList.count } }

Upvotes: 0

Deryck Lucian
Deryck Lucian

Reputation: 475

I will suggest you to change the filter process (smth like this):

func filterContentForSearchText(_ searchText: String) {

    let pred = NSPredicate(format: "name contains[cd] %@", searchText)
    filteredHotels = hotelList?.filtered(using: pred) as? [hotelsModel]

    tableView.reloadData()
}

and change the isSearching variable to this:

var isSearching: Bool {
    return searchBar.text != ""
}

Use the debugger to see the indexPath.row value on the line that is causing your crash.

Upvotes: 1

Related Questions