Skip to content

Instantly share code, notes, and snippets.

@hassanvfx
Created October 2, 2019 00:08
Show Gist options
  • Save hassanvfx/9931bfbfe5b8a6c2c4452c00dd1a6380 to your computer and use it in GitHub Desktop.
Save hassanvfx/9931bfbfe5b8a6c2c4452c00dd1a6380 to your computer and use it in GitHub Desktop.
import UIKit
import Alamofire
import AlamofireObjectMapper
import ObjectMapper
typealias APIClosure<K> = (K?)->Void
class APIService: NSObject {
static let API_KEY_V3 = "SECRET_KEY"
static let QUEUE = DispatchQueue(label: "com.test.api", qos: .background, attributes: .concurrent)
static func get<K:Mappable>(_ endpoint:APIEndpoints, completion: @escaping APIClosure<K>) -> Void {
APIService.get(endpoint.url(), completion: completion)
}
static func get<K:Mappable>(_ endpointURL:String, completion: @escaping APIClosure<K>) -> Void {
Alamofire.request(endpointURL).responseObject(queue: APIService.QUEUE) { (response: DataResponse<K>) in
guard let response = response.result.value else {
assert(false, "Unexpected response format")
completion(nil)
}
DispatchQueue.main.async {
completion(response)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment