-
-
Save anupamchugh/40a68d0a88a4df63d89620c99e72a762 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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