Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created March 5, 2020 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anupamchugh/40a68d0a88a4df63d89620c99e72a762 to your computer and use it in GitHub Desktop.
Save anupamchugh/40a68d0a88a4df63d89620c99e72a762 to your computer and use it in GitHub Desktop.
struct StockPrice : Codable{
let open: String
let close: String
let high: String
let low: String
private enum CodingKeys: String, CodingKey {
case open = "1. open"
case high = "2. high"
case low = "3. low"
case close = "4. close"
}
}
struct StocksDaily : Codable {
let timeSeriesDaily: [String: StockPrice]?
private enum CodingKeys: String, CodingKey {
case timeSeriesDaily = "Time Series (Daily)"
}
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
timeSeriesDaily = try (values.decodeIfPresent([String : StockPrice].self, forKey: .timeSeriesDaily))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment