Skip to content

Instantly share code, notes, and snippets.

@serhiybutz
Created July 20, 2020 23:55
Show Gist options
  • Save serhiybutz/578ae9b7860d28da24a956d8fad60de6 to your computer and use it in GitHub Desktop.
Save serhiybutz/578ae9b7860d28da24a956d8fad60de6 to your computer and use it in GitHub Desktop.
Combine: withLatestFrom, 02
var cancellables = Set<AnyCancellable>()
func setupPipelines() {
let searchPublisher = searchBar.searchTextField.textPublisher
.prepend(searchBar.text!)
.eraseToAnyPublisher()
let sparsedSearchPublisher = searchPublisher
.debounce(for: .seconds(0.3), scheduler: DispatchQueue.main)
.eraseToAnyPublisher()
sparsedSearchPublisher
.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