SHARE
TWEET

Untitled

a guest Sep 15th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Foundation
  2.  
  3. class Network {
  4.    
  5.    
  6.     private let apikey = "71f3bc8d41181084e31b"
  7.     private let url = "https://free.currconv.com/api/v7/convert"
  8.     private var myCurrency: Response?
  9.    
  10.     func getCurrentCurrency(complition: @escaping (Response)->Void) {
  11.         var urlComponents = URLComponents(string: url)
  12.         urlComponents?.queryItems = [
  13.             URLQueryItem(name: "q", value: "USD_BYN,BYN_USD"),
  14.             URLQueryItem(name: "compact", value: "ultra"),
  15.             URLQueryItem(name: "apiKey", value: "\(apikey)")
  16.         ]
  17.         let url = urlComponents?.url
  18.        
  19.         let task = URLSession.shared.dataTask(with: url!) {
  20.             (data, response, error) in
  21.            
  22.             guard let data = data else { return }
  23.             guard let currency: Response = try? JSONDecoder().decode(Response.self, from: data) else {
  24.                 print("Error can't parse")
  25.                 return
  26.             }
  27.             return complition(currency)
  28.         }
  29.         task.resume()
  30.        
  31.     }
  32.    
  33. }
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