Slide 42
Slide 42 text
/463-4FTTJPOͷSY@SFTQPOTF
42
func rx_response(request: NSURLRequest) -> Observable<(NSData, NSHTTPURLResponse)> {
return Observable.create { observer in
let task = self.dataTaskWithRequest(request) { (data, response, error) in
guard let response = response, data = data else {
observer.on(.Error(error ?? RxCocoaURLError.Unknown))
return
}
guard let httpResponse = response as? NSHTTPURLResponse else {
observer.on(.Error(RxCocoaURLError.NonHTTPResponse(response: response)))
return
}
observer.on(.Next(data, httpResponse))
observer.on(.Completed)
}
let t = task
t.resume()
return AnonymousDisposable {
task.cancel()
}
}
}
https://github.com/ReactiveX/RxSwift/blob/2.4/
RxCocoa/Common/Observables/NSURLSession+Rx.swift
この部分の実⾏スレッドはRxの機能では指定できない