Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NetworkManager {
- private init() {}
- static let shared = NetworkManager()
- private let apikey = "Your Api Key"
- private let url = "https://free.currconv.com/api/v7/convert"
- func getCurrentCurrency(complition: @escaping (Response)->Void) {
- var urlComponents = URLComponents(string: url)
- urlComponents?.queryItems = [
- URLQueryItem(name: "q", value: "USD_BYN,BYN_USD"),
- URLQueryItem(name: "compact", value: "ultra"),
- URLQueryItem(name: "apiKey", value: "\(apikey)")
- ]
- let url = urlComponents?.url
- let task = URLSession.shared.dataTask(with: url!) {
- (data, response, error) in
- guard let data = data else { return }
- guard let currency: Response = try? JSONDecoder().decode(Response.self, from: data) else {
- print("Error can't parse")
- return
- }
- return complition(currency)
- }
- task.resume()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement