Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement