Created
October 2, 2019 00:08
-
-
Save hassanvfx/9931bfbfe5b8a6c2c4452c00dd1a6380 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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