Guest User

Untitled

a guest
Jan 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. URLSession.shared.dataTask(with: URL(string: "https://api.openweathermap.org/data/2.5/weather?q=(city),(countryCode)&appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxx”)!) { data, response, error in
  2. if let error = error {
  3. print("Error:n(error)")
  4. } else {
  5. do {
  6. let weather = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String: AnyObject]
  7. self.weatherLabel.stringValue = "Temperature (weather["main"]!["temp"]!!)°CnHumidity (weather["main"]!["humidity"]!!)%nPressure (weather["main"]!["pressure"]!!)hPa."
  8. }
  9. catch let jsonError as NSError {
  10. print("JSON error:n(jsonError.description)")
  11. }
  12. }
  13. }.resume()
Add Comment
Please, Sign In to add comment