Skip to content

Instantly share code, notes, and snippets.

@serhiybutz
Created July 21, 2020 16:37
Show Gist options
  • Save serhiybutz/6d86106f511c235f2127e7ae07624c9d to your computer and use it in GitHub Desktop.
Save serhiybutz/6d86106f511c235f2127e7ae07624c9d to your computer and use it in GitHub Desktop.
Combine: withLatestFrom, 02
var cancellables = Set<AnyCancellable>()
func setupStreams() {
let searchStream = searchBar.searchTextField.textPublisher
.prepend(searchBar.text!)
.eraseToAnyPublisher()
let sparsedSearchStream = searchStream
.debounce(for: .seconds(0.3), scheduler: DispatchQueue.main)
.eraseToAnyPublisher()
sparsedSearchStream
.sink(
receiveValue: { searchText in
self.doSearching(by: searchText ?? "")
})
.store(in: &cancellables)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment