I try to implement Search as you type written in Swift. It works already but I need some tuning. I send with each letter typed in
func searchBar(searchBar: UISe
The problem you're having is that you're debouncing the findUser
function before calling it every time. Your debouncing function sets up the initial timer and delay, but since you're calling it each time, the initial timer is always "now". You should debounce only once so the closure can maintain its captured last-executed time.
You want to only call debounce
one time and store it as a property, like so:
class MySearchController: ... {
lazy var debouncedFindUser = debounce(
Static.searchDebounceInterval,
Static.q,
self.findUser)
...
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
debouncedFindUser()
}
func findUser() {
...
}
}