So my UICollectionView has 2 cells:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
var imageCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as? CollectionViewCell
var videoCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellVideo", forIndexPath: indexPath) as? CollectionViewCell
if (imageCell != nil) { // Image Cell
println("image cell exist")
return imageCell!
}
if (videoCell != nil) { // Video Cell
println("video cell exist")
return videoCell!
}
}
Somehow I get error Missing return in a function expected to return 'UICollectionViewCell'
. Why is that when I have return in both the if
? I might think it is because I use return 2 times, or?
EDIT:
I also tried this, but does not work either:
var myUrl = "Url to file from web"
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
var imageCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as? CollectionViewCell
var videoCell = collectionView.dequeueReusableCellWithReuseIdentifier("cellVideo", forIndexPath: indexPath) as? CollectionViewCell
if myUrl.rangeOfString(".png") != nil{ // If string contains .png it should use a imageCell
println("exists")
return imageCell!
}
if myUrl.rangeOfString(".mp4") != nil{ // If string contains .mp4 it should use a videoCell
println("exists")
return videoCell!
}
}