Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created April 21, 2021 06:20
Show Gist options
  • Save KrauserHuang/1a8b72198e5c1e020d76329a6373197d to your computer and use it in GitHub Desktop.
Save KrauserHuang/1a8b72198e5c1e020d76329a6373197d to your computer and use it in GitHub Desktop.
func fetchMusic() {
if let urlStr = "https://itunes.apple.com/search?term=宇多田光&media=music&country=JP".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
if let url = URL(string: urlStr) {
URLSession.shared.dataTask(with: url) { (data, response, error) in
if let data = data {
let decoder = JSONDecoder()
do {
let result = try decoder.decode(MusicOnline.self, from: data)
self.showOnlineFile = result.results
} catch {
print(error)
}
}
}.resume()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment