Created
July 21, 2020 16:37
-
-
Save serhiybutz/6d86106f511c235f2127e7ae07624c9d to your computer and use it in GitHub Desktop.
Combine: withLatestFrom, 02
This file contains 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
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