ios - Filter searchText to tableView -
right using following
let data = ["new york, ny", "los angeles, ca" . . .] var filtereddata: [string]! filtereddata = data
but want use firebase, identical structure, using this
var data = [categories]()
(this categories
)
struct categories { let key:string! let content:string! let itemref:firdatabasereference? init (content:string, key:string = "") { self.key = key self.content = content self.itemref = nil } init (snapshot:firdatasnapshot) { key = snapshot.key itemref = snapshot.ref if let categoriescontent = snapshot.value!["content"] as? string { content = categoriescontent } else { content = "" } }
}
so when search these lines supposed filter out aren't correct
func searchbar(searchbar: uisearchbar, textdidchange searchtext: string) { // unhide tableview, changed method tableview.hidden = false filtereddata = searchtext.isempty ? data : data.filter({(datastring: string) -> bool in // if dataitem matches searchtext, return true include return datastring.rangeofstring(searchtext) != nil }) tableview.reloaddata() }
but since filter({(datastring: string)
takes strings not work
question : there other way replace string firebase struct?
thanks lot!
this tutorial clear in uisearchresultsupdating , filtering section.
Comments
Post a Comment