Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RxSwift x APIKit
import Foundation
import APIKit
import RxSwift
extension Session {
func rx_sendRequest<T: RequestType>(request: T) -> Observable<T.Response> {
return Observable.create { observer in
let task = self.sendRequest(request) { result in
switch result {
case .Success(let res):
observer.on(.Next(res))
observer.on(.Completed)
case .Failure(let err):
observer.onError(err)
}
}
return AnonymousDisposable { [weak task] in
task?.cancel()
}
}
}
class func rx_sendRequest<T: RequestType>(request: T) -> Observable<T.Response> {
return sharedSession.rx_sendRequest(request)
}
}
@sohayb

This comment has been minimized.

Copy link

sohayb commented Feb 18, 2017

Thank you! this was quite helpful. For those looking for an updated version (swift 3.0 and RxSwift 3.0) check this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.