title: Collection view reusing images while scrolling in swift 2
body: <p>I'm simply desperate, searched for 6 hours now and can't seem to find an answer.</p>
  
  <p>I have a collection view with images loaded from a remote server and while scrolling the cells are being refreshed with previous images for a few seconds before settling.
  Tried overriding "prepare for reuse" and setting the imageview image to nil but it is still not working..
  Would appreciate an example from someone who got it working,</p>
  
  <p>thanks a lot!</p>
  
  <p><strong>EDIT - ADDING THE CODE</strong></p>
  
  <p>CollectionView:</p>
  
  <pre><code>func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath:indexPath) as! PictureCell
  
      cell.pictureCD = GalleryCD().fetchTable()[indexPath.row]
  
      return cell
  }
  </code></pre>
  
  <p>CollectionViewCell:</p>
  
  <pre><code>class PictureCell: UICollectionViewCell {
  @IBOutlet weak var picture: UIImageView!
  
  var pictureCD: NSManagedObject! {
      didSet { self.setupData() }
  }
  
  override func prepareForReuse() {
      super.prepareForReuse()
  
      self.picture.image = nil
      self.picture.setNeedsDisplay() // tried adding after some recommendations
      self.setNeedsDisplay()         // tried adding after some recommendations
  }
  
  func setupData(){
      self.picture.image = UIImage(named: "blank")
  
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
          let URL = (NSURL (string: url.pictureSquareGET(picture: self.pictureCD)))!
  
          let data = NSData(contentsOfURL: URL)!
  
          dispatch_async(dispatch_get_main_queue()) {
              self.picture.image = UIImage(data: data)
          }
      })
  }
  </code></pre>
  
  <p>}</p>