Final
unknown
swift
4 years ago
614 B
21
Indexable
internal struct Coin: Decodable {
internal let coinInfo: [String: CoinInfo]
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
coinInfo = try container.decode([String: CoinInfo].self)
}
}
internal struct CoinInfo: Decodable {
internal let usd, usd_market_cap, usd_24h_vol, usd_24h_change: Float
internal let last_updated_at: Int
}
do {
let data = try JSONDecoder().decode(Coin.self, from: undecodedData)
let coins = data.coinInfo
let ethereumData = coins["ethereum"]
print(ethereumData)
} catch let err {
print(err)
}
Editor is loading...