Skip to content

Instantly share code, notes, and snippets.

@jamiepinkham
Created April 5, 2016 13:34
Show Gist options
  • Save jamiepinkham/cccbcb8c12bfa705c76137b7a086b7fe to your computer and use it in GitHub Desktop.
Save jamiepinkham/cccbcb8c12bfa705c76137b7a086b7fe to your computer and use it in GitHub Desktop.
struct Result {
let text: String
let someOtherThing: String
}
struct Fetcher {
static func performQuery(query: String) -> Observable<[Result]> {
//returns an observable that hits the network, whose dispose action is to cancel the network request
}
}
class ViewController: UIViewController {
weak var textField: UITextField!
override func viewDidLoad() {
let o: Observable<[String]> =
textField.rx_text
.throttle(0.3)
.distinctUntilChanged()
.flatMapLatest { query in
Fetcher.performQuery(query)
}.map { $0.map { $0.text }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment