Created
February 20, 2020 00:06
-
-
Save salmanfakhri/442861eb2bf221ef64c99a0d247c09be to your computer and use it in GitHub Desktop.
This file contains 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
let endpoint = "https://api.openweathermap.org/data/2.5/weather?zip=08901,us&appid=<INSERT API KEY HERE>" | |
let url = URL(string: endpoint)! | |
URLSession.shared.dataTask(with: url) { (data, response, error) in | |
if let error = error { | |
print(error) | |
return | |
} | |
guard let data = data else { | |
return | |
} | |
do { | |
let weatherData = try JSONDecoder().decode(WeatherResponse.self, from: data) | |
DispatchQueue.main.async { | |
self.currentWeatherData = weatherData | |
} | |
} catch { | |
print(error) | |
} | |
}.resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment