Advertisement
Larme

Untitled

Nov 6th, 2020
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.89 KB | None | 0 0
  1. First step:
  2.  
  3.     struct Response: Codable {
  4.         let dates: [String: CustomDate]
  5.         let metadata: Metadata
  6.         let total: Total
  7.         let updated_at: String //Should be a date, but that adds another complexity
  8.     }
  9.    
  10.     struct CustomDate: Codable {
  11.         let countries: [String: Country]
  12.         let info: Infos
  13.     }
  14.    
  15.     struct Infos: Codable {
  16.         let date: String
  17.         let date_generation: String
  18.         let yesterday: String
  19.     }
  20.    
  21.     struct Country: Codable {
  22.         let date: String
  23.         let name: String
  24.     }
  25.    
  26.     struct Metadata: Codable {
  27.         let by: String
  28.         let url: [String]
  29.     }
  30.    
  31.     struct Total: Codable {
  32.         let name: String
  33.     }
  34.  
  35. I skipped a few things, but it works then with:
  36.  
  37.     let foundDate = values.dates["2020-11-04"]?.countries["Afghanistan"]?.date
  38.     print(foundDate)
  39.  
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement