wilk_maciej

pogoda

May 29th, 2020
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.06 KB | None | 0 0
  1. struct Day: Codable{
  2.     let id: Int
  3.     let weather_state_name: String
  4.     let weather_state_abbr: String
  5.     let wind_direction_compass: String
  6.     let created: String
  7.     let applicable_date: String
  8.     let min_temp: Float
  9.     let max_temp: Float
  10.     let the_temp: Float
  11.     let wind_speed: Float
  12.     let wind_direction: Float
  13.     let air_pressure: Float
  14.     let humidity: Int
  15.     let visibility: Float
  16.     let predictability: Int
  17. }
  18.  
  19. struct Entry: Codable {
  20.     let days: [String: Day]
  21. }
  22.  
  23. print("robi cokolwiekddddddd")
  24. let url = URL(string: "https://www.metaweather.com/api/location/523920/")
  25. if let url = URL(string: "https://www.metaweather.com/api/location/523920/") {
  26.    URLSession.shared.dataTask(with: url) { data, response, error in
  27. if let data = data {
  28. let jsonDecoder = JSONDecoder()
  29. do {
  30. let parsedJSON = try jsonDecoder.decode(Entry.self, from: data)
  31. for day in parsedJSON.days {
  32. print(day.value.id)
  33. print(day.value.humidity)
  34.             }
  35.         } catch {
  36. print(error)
  37.         }
  38.        }
  39.    }.resume()
  40. }
  41. print("robi cokolwiek")
Add Comment
Please, Sign In to add comment