What should be the best approach to decode the chart data for songs?
For example -
struct Charts: Decodable {
let results: Songs
}
struct Songs: Codable {
let songs: [ChartsSong]
}
struct ChartsSong: Codable {
let data: [Song]
let orderID, next, chart, name: String
let href: String
enum CodingKeys: String, CodingKey {
case data
case orderID = "orderId"
case next, chart, name, href
}
}
let url = URL(string: "https://api.music.apple.com/v1/catalog/us/charts?types=songs&genre=20&limit=1")!
let musicRequest = MusicDataRequest(urlRequest: URLRequest(url: url))
let response = try await musicRequest.response()
let data = try JSONDecoder().decode(Charts.self, from: response.data)
Right now, I'm using a custom structure to decode the data with the ChartsSong
struct. Do you think there's a possibility of a Chart item in the future? Should I file feedback stating my use case?