0

I created a custom UICollectionViewCell and I tried to reference it from UICollectionView delegate method cellForItemAtIndexPath and I keep getting Cannot assign value of type 'UICollectionViewCell' to type 'GridViewCell'

Delegate Method

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let asset = self.assetsFetchResults[indexPath.item] as! PHAsset
    var cell = GridViewCell()

    //Deque an GridViewCell
    cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath)
    cell.representedAssetIdentifier = asset.localIdentifier


    return cell
}

GridViewCell class

import UIKit

class GridViewCell: UICollectionViewCell {

@IBOutlet weak var imageView: UIImageView!
var thumbnailImage = UIImage()
var representedAssetIdentifier = NSString()

override func prepareForReuse() {
    super.prepareForReuse()
    self.imageView.image = nil
}

//func setThumbnailImage(thumbnailImage: UIImage) {
//    self.imageView.image = thumbnailImage
//}
}
Leo
  • 24,596
  • 11
  • 71
  • 92
Tonespy
  • 3,257
  • 7
  • 26
  • 52

1 Answers1

1

Replace

cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath)

With

cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath) as! GridViewCell
beyowulf
  • 15,101
  • 2
  • 34
  • 40