Skip to content

Instantly share code, notes, and snippets.

@therohansanap
Created April 5, 2020 10:26
Show Gist options
  • Select an option

  • Save therohansanap/5375f40d5e1c90a66f9ad23746402a6a to your computer and use it in GitHub Desktop.

Select an option

Save therohansanap/5375f40d5e1c90a66f9ad23746402a6a to your computer and use it in GitHub Desktop.
let results = query.rx.text.asDriver() // This converts a normal sequence into a `Driver` sequence.
.throttle(.milliseconds(300), scheduler: MainScheduler.instance)
.flatMapLatest { query in
fetchAutoCompleteItems(query)
.asDriver(onErrorJustReturn: []) // Builder just needs info about what to return in case of error.
}
results
.map { "\($0.count)" }
.drive(resultCount.rx.text)
.disposed(by: disposeBag)
results
.drive(resultsTableView.rx.items(cellIdentifier: "Cell")) { (_, result, cell) in
cell.textLabel?.text = "\(result)"
}
.disposed(by: disposeBag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment