Skip to content

Instantly share code, notes, and snippets.

@salmanfakhri
Created February 20, 2020 00:06
Show Gist options
  • Save salmanfakhri/442861eb2bf221ef64c99a0d247c09be to your computer and use it in GitHub Desktop.
Save salmanfakhri/442861eb2bf221ef64c99a0d247c09be to your computer and use it in GitHub Desktop.
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