Created
April 21, 2021 06:20
-
-
Save KrauserHuang/1a8b72198e5c1e020d76329a6373197d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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