Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created December 29, 2020 03:18
Show Gist options
  • Save KrauserHuang/cab3e6fa1226f98554750bc4b270e58d to your computer and use it in GitHub Desktop.
Save KrauserHuang/cab3e6fa1226f98554750bc4b270e58d to your computer and use it in GitHub Desktop.
//照片牆部分
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PropertyKeys.imageCell, for: indexPath) as! PostGridCollectionViewCell
//將圖片透過data抓下來變成image再回傳給cell
if let postImageURL = igposts[indexPath.item].node.thumbnail_src,
let url = URL(string: postImageURL) {
URLSession.shared.dataTask(with: url) { (data, response, error) in
if let data = data {
DispatchQueue.main.async {
cell.postGridImageView.image = UIImage(data: data)
}
}
}.resume()
}
return cell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment