Created
April 30, 2020 18:19
-
-
Save azamsharp/a016243aeea193059a596e906772df30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Webservice.swift | |
// COVID19App | |
// | |
// Created by Mohammad Azam on 4/29/20. | |
// Copyright © 2020 Mohammad Azam. All rights reserved. | |
// | |
import Foundation | |
class Webservice { | |
func getCovidTrackingResult(completion: @escaping ([Tracking]?) -> Void) { | |
guard let url = URL(string: "https://covidtracking.com/api/v1/states/current.json") else { | |
fatalError("Invalid URL") | |
} | |
URLSession.shared.dataTask(with: url) { data, response, error in | |
guard let data = data, error == nil else { | |
return completion(nil) | |
} | |
let trackingList = try? JSONDecoder().decode([Tracking].self, from: data) | |
completion(trackingList) | |
}.resume() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment