0

I'm working on project in swift 3 and as to cache the image url that I get from json response I use the kingfisher pod. But for some reason I'm not getting the image in my UICollectionViewCell at all (image not getting displaying). What am I missing here. My code as below:

extension TableViewCell: UICollectionViewDelegate, UICollectionViewDataSource {


    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
          return arrayJson.count
    }

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

          cell.naeLabel.text = arrayJson[indexPath.row]?["title"].stringValue
        let url = ImageResource(downloadURL: URL(string: (arrayJson[indexPath.row]?["url"].stringValue)!)!, cacheKey: (arrayJson[indexPath.row]?["url"].stringValue))

        cell.ProfileimageView.kf.setImage(with: url)

        return cell    
    }
}
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
danutha
  • 214
  • 3
  • 16
  • can you print your `arrayJson` – Anbu.Karthik Mar 14 '17 at 05:49
  • I assign all the properties to the cell as i have assigned it in the "naeLabel.text" in the code above. Therefore inside the arrayJson i have a string called "url" which i need too set it to "ProfileimageView". arrayJson [ "title":"name","url":"https://storage.cloud.google.com/feisty-beacon-159305.appspot.com/audio_75px/audio5_75px.jpg?_ga=1.66550766.1112221525.1486464661"] – danutha Mar 14 '17 at 05:54
  • Safely unwrap all your optionals before using the string value, so that the url isn't invalid because of "Optional(...)". Also don't specify a cacheKey manually, Kingfisher will use the url automatically as the cache key. – Eric Aya Apr 09 '17 at 14:06

0 Answers0