Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement