Skip to content

Instantly share code, notes, and snippets.

@hassanvfx
Last active October 1, 2019 23:56
Show Gist options
  • Save hassanvfx/11b89759c21dfc6868620ce5cbf24b09 to your computer and use it in GitHub Desktop.
Save hassanvfx/11b89759c21dfc6868620ce5cbf24b09 to your computer and use it in GitHub Desktop.
import UIKit
import RxSwift
import Alamofire
import AlamofireObjectMapper
extension Reactive where Base:APIService{
func call<K:APIResponse>(_ endpoint : APIEndpoints) -> Single<K> {
return Single<K>.create { single in
let finish:APIClosure<K> = { response in
guard let resource = response else {
assert(false, "Unexpected response format")
single(.error(Services.error.type(.networkFailure)))
}
DispatchQueue.main.async {
single(.success(resource))
}
}
switch endpoint{
case .getMovie:
APIService
.get(endpoint,completion: finish as! APIClosure<Movie>)
case .getMovieRelated, .getTrendingMovies:
APIService
.get(endpoint,completion: finish as! APIClosure<APIResponseMovieList>)
}
return Disposables.create()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment