[Chapter 10]: NASA API changed on ya

Looks like there was a change to the API and there’s now not necessarily a value returned for closed on Events anymore. I was getting empty arrays of events until I deleted let closeDate = json["closed"] as? String from the main guard statement, and replaced the self.closeDate assignment as follows:

if let closeDate = json["closed"] as? String {
  self.closeDate = EONET.ISODateReader.date(from: closeDate)
} else {
  self.closeDate = nil
}

Might not be a bad argument for shifting all the JSON parsing to Codable in the future - at least at that point it’d scream real loud when something like this happens.

Something to address in the next edition @fpillet :point_up_2:t3:

Thanks for noticing the change and suggesting a workaround! We’ll address this in the next edition of the book :ok_hand:

This topic was automatically closed after 166 days. New replies are no longer allowed.