SHARE
TWEET

Untitled

a guest Oct 20th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct WeatherResponse: Codable {
  2.     var latitude: Double?
  3.     var longitude: Double?
  4.     var timezone: String?
  5.     var currently: Weather?
  6.     var minutely: WeatherContainer?
  7.     var hourly: WeatherContainer?
  8.     var daily: WeatherContainer?
  9.     var alerts: [Alert]?
  10.     var flags: Flags?
  11.     var offset: Int?
  12. }
  13.  
  14. struct Weather: Codable {
  15.     var time: Int?
  16.     var summary: String?
  17.     var icon: WeatherType?
  18.     var nearestStormDistance: Int?
  19.     var precipIntensity: Double?
  20.     var precipIntensityError: Double?
  21.     var precipProbability: Double?
  22.     var precipType: String?
  23.     var temperature: Double?
  24.     var apparentTemperature: Double?
  25.     var dewPoint: Double?
  26.     var humidity: Double?
  27.     var pressure: Double?
  28.     var windSpeed: Double?
  29.     var windGust: Double?
  30.     var windBearing: Double?
  31.     var cloudCover: Double?
  32.     var uvIndex: Int?
  33.     var visibility: Double?
  34.     var ozone: Double?
  35. }
  36.  
  37. struct WeatherContainer: Codable {
  38.     var summary: String?
  39.     var icon: WeatherType?
  40.     var data: [Weather]?
  41. }
  42.  
  43. struct Alert: Codable {
  44.     var title: String?
  45.     var time: Int?
  46.     var expires: Int?
  47.     var description: String?
  48. }
  49.  
  50. struct Flags: Codable {
  51.     var sources: [String]?
  52.     var nearestStation: Double?
  53.     var units: String?
  54.    
  55.     enum CodingKeys: String, CodingKey {
  56.         case sources
  57.         case nearestStation = "nearest-station"
  58.         case units
  59.     }
  60. }
  61.  
  62. enum WeatherType: String, Codable {
  63.     case clearDay = "clear-day"
  64.     case clearNight = "clear-night"
  65.     case rain = "rain"
  66.     case snow = "snow"
  67.     case sleet = "sleet"
  68.     case wind = "wind"
  69.     case fog = "fog"
  70.     case cloudy = "cloudy"
  71.     case partlyCloudyDay = "partly-cloudy-day"
  72.     case partlyCloudyNight = "partly-cloudy-night"
  73.     case unknown
  74.    
  75.     init(from decoder: Decoder) throws {
  76.         self = try WeatherType(rawValue: decoder.singleValueContainer().decode(RawValue.self)) ?? .unknown
  77.     }
  78.    
  79.     var icon: String {
  80.         switch self {
  81.         case .clearDay:
  82.             return "sunny"
  83.         case .clearNight:
  84.             return "clearnight"
  85.         case .rain:
  86.             return "moderaterain"
  87.         case .snow:
  88.             return "snowy"
  89.         case .sleet:
  90.             return "snowy"
  91.         case .wind:
  92.             return "windy"
  93.         case .fog:
  94.             return "fog"
  95.         case .cloudy:
  96.             return "overcast"
  97.         case .partlyCloudyDay:
  98.             return "partlycloudy"
  99.         case .partlyCloudyNight:
  100.             return "clearnight"
  101.         case .unknown:
  102.             return ""
  103.         }
  104.     }
  105. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top