I have UITextField for entering search string and UITableView with results. What i want is to run search function when user entered more than 3 letters and it at least 0,5 sec passed since last symbol added to UITextView.
I found (Detect when user stopped / paused typing in Swift) function and I added it to my ViewController that have class SearchVC and method server_search
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
NSObject.cancelPreviousPerformRequests(
withTarget: self,
selector: #selector(SearchVC.server_search),
object: textField)
self.perform(
#selector(SearchVC.server_search),
with: textField,
afterDelay: 0.5)
return true
}
But nothing happens.