Skip to content

Instantly share code, notes, and snippets.

@serhiybutz
Created July 21, 2020 16:15
Show Gist options
  • Save serhiybutz/7076057be740db85d497f7ebf0d7632d to your computer and use it in GitHub Desktop.
Save serhiybutz/7076057be740db85d497f7ebf0d7632d to your computer and use it in GitHub Desktop.
Combine: withLatestFrom, 02
var cancellables = Set<AnyCancellable>()
func setupStreams() {
let searchStream = searchBar.searchTextField.textStream
.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