Created
December 29, 2020 02:30
-
-
Save KrauserHuang/25f2953a3d0399abe10e905a563ac665 to your computer and use it in GitHub Desktop.
This file contains 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 fetchData() { | |
//使用URLSession來抓取需要的資料 | |
let urlStr = "https://www.instagram.com/scottcbakken/?__a=1" | |
if let url = URL(string: urlStr) { | |
URLSession.shared.dataTask(with: url) { (data, response, error) in | |
let decoder = JSONDecoder() | |
decoder.dateDecodingStrategy = .secondsSince1970 | |
if let data = data, | |
let renderData = try? decoder.decode(InstagramData.self, from: data) { | |
self.igdata = renderData | |
self.igposts = renderData.graphql.user.edge_owner_to_timeline_media.edges | |
DispatchQueue.main.async { | |
self.collectionView.reloadData() | |
} | |
} | |
}.resume() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment