Created
August 30, 2021 12:15
-
-
Save lalkrishna/60f16a49de5940a3207991f47e711449 to your computer and use it in GitHub Desktop.
Throttled / Incremental search on Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { | |
guard !searchText.isEmpty else { searchQuery(); return } | |
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(searchQuery), object: nil) | |
perform(#selector(searchQuery), with: nil, afterDelay: 0.4) | |
} | |
@objc func searchQuery() { | |
guard let searchText = searchBar.text else { return } | |
// Call API | |
} | |
// https://www.linkedin.com/in/lal-krishna-dev/ |
Option 3:
Combine with debounce
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Option 2:
DispatchWorkItem