ios - Sqlite.swift live search -
i want live search on db.
lets want search companies , have following info on column named companies.
- fastcompany
- microsoft
i have textfield has calls function on editchanged.
@ibaction func searching(sender: anyobject) { tempstring = "%"+searchbar.text+"%" println(tempstring) user = user.select(name) .filter(like(tempstring, name)) .limit(30, offset: 0) collectionview?.reloaddata() }
it kind of works, if start typing "fa" show (facebook, facebook , fastcompany)
if continue typing "fac" show (facebook, facebook)
but when delete last character "c" searchbox (leaving in "fa" again) query displays nothing.
any ideas on how can solve this.
i think issue coming on writing user
object each search. fine long move forward, when go backwards did, query messes up.
instead, try adding currentquery
property view controller collection view in , set user.select
statement.
currentquery = user.select(name) .filter(like(tempstring, name)) .limit(30, offset: 0)
then use currentquery
object display results instead. way, no matter you're searching, match everything.
Comments
Post a Comment