title: How to display array of images on Collection View in Swift
body: <pre><code>func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      return 1
  }
  
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
       print("gallery count : \(self.arrayGallerySingle.count)")
      return self.arrayGallerySingle.count
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gallerycell", for: indexPath) as! GalleryViewCell
  return cell
  }
  
  //API Fetching method
  func galleryFetch(){
  
      let prs = [
          "id": dealIDGallery,
          "deal_single_page": "1" as String
      ]
  
      Service.StartWithoutLoading(prs as [String : AnyObject]?, onCompletion: { result in
          let jsonResponseSingle = result as? NSDictionary
          print(" jsonResponse\(String(describing: jsonResponseSingle))")
  
          if let resultGallery = jsonResponseSingle?.value(forKey: "result") as? NSArray{
  
              for keyValuesGallery in resultGallery {
  
                  let gallerySingle = (keyValuesGallery as AnyObject).value(forKey: "gallery_images") as? NSArray
  
                  print("Gallery Images Key: \(gallerySingle)")
                  self.arrayGallerySingle = gallerySingle as! [AnyObject]
  
                  DispatchQueue.main.async { () -&gt; Void in
                      self.collectionView?.reloadData()
  
                  }
              }
  
          }
      })
  }
  </code></pre>
  
  <p>How will I show an array of images with key <code>gallery_images</code> on UICollectionViewCell?This line <code>print("Gallery Images Key: \(gallerySingle)")</code> prints the required array of images on console but I am unable to show on <code>collectionView</code>. My <code>JSON</code> response is <a href="http://www.jsoneditoronline.org/?id=8eccb63976d76be7d0b2d1b0e8f02306" rel="nofollow noreferrer">http://www.jsoneditoronline.org/?id=8eccb63976d76be7d0b2d1b0e8f02306</a>. I am using <code>SDWebImage</code> in my project also.I already checked <code>datasource</code> connection &amp; <code>collectionView</code> IBoutlet as well as an image inside the cell. I am a beginner in Swift pls help and if required any further information pls ask</p>