Get Apple lookup using codable.

平成30年2月19日(月曜日)

//------------------------------------------
import UIKit

//: Playground - noun: a place where people can play

import UIKit

struct Itunes_lookup: Codable {
    struct Data: Codable {
        let formattedPrice: String
        var trackName: String
        var artworkUrl60: String
    }
    var resultCount: Int
    var results: [Data]
}

let url = URL(string: "https://itunes.apple.com/jp/lookup?id=1135688400")!

let decoder: JSONDecoder = JSONDecoder()

do {
    let data = try Data(contentsOf: url, options: [])
    let rss = try decoder.decode(Itunes_lookup.self, from: data)
    print(rss)
    print(rss.results[0].artworkUrl60)
    print(rss.results[0].trackName)
    print(rss.results[0].formattedPrice)
} catch {
    print(error)
}
//------------------------------------------

参考url
struct Codable
Swift Codable With Custom Dates
[iOS][Swift 4] CodableでJSONのパース
iTunes Search API