SHARE
TWEET

Untitled

a guest Oct 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import UIKit
  2. import Alamofire
  3. import AlamofireObjectMapper
  4. import ObjectMapper
  5.  
  6. typealias APIClosure<K> = (K?)->Void
  7.  
  8. class APIService: NSObject {
  9.    
  10.     static let API_KEY_V3 = "SECRET_KEY"
  11.     static let QUEUE = DispatchQueue(label: "com.test.api", qos: .background, attributes: .concurrent)
  12.    
  13.    
  14.     static func get<K:Mappable>(_ endpoint:APIEndpoints, completion: @escaping APIClosure<K>) -> Void {
  15.         APIService.get(endpoint.url(), completion: completion)
  16.     }
  17.    
  18.     static func get<K:Mappable>(_ endpointURL:String, completion: @escaping APIClosure<K>) -> Void {
  19.        
  20.         Alamofire.request(endpointURL).responseObject(queue: APIService.QUEUE) { (response: DataResponse<K>) in
  21.            
  22.             guard let response = response.result.value else {
  23.                 assert(false, "Unexpected response format")
  24.                 completion(nil)
  25.             }
  26.            
  27.             DispatchQueue.main.async {
  28.                 completion(response)
  29.             }
  30.         }
  31.     }
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top