0

I want to show Flickr images in a collection view. Here's how I fetch the images in viewDidLoad():

FlickrApi.fetchPhotos(completion: { photos, error in
    self.photos = photos as! [URL]
    self.collectionView?.reloadData()
})

The images get fetched but they don't show up as UIImageView in cellForItemAt method of UICollectionView. Instead, I get:

unexpectedly found nil while unwrapping an Optional value

where I load the images for the cell even though the self.photos gets populated with image URLs before I load the images like so:

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! FlickrCell

    cell.flickrPhoto.pin_setImage(from: self.photos[indexPath.row])

    return cell
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
waseefakhtar
  • 1,373
  • 2
  • 24
  • 47

0 Answers0