Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast Enumeration through UICollectionView Cells - Swift

I am trying to fast enumerate through all of my collection view cells, however this implementation below is giving me a warning.

for cell in self.collectionView?.visibleCells() as [UICollectionViewCell] {

    // Do Stuff
}

Error below appears on first line:

Operand of postfix '?' should have optional type; type is '(UICollectionView, cellForItemAtIndexPath: NSIndexPath) -> UICollectionViewCell'

I've tried messing around with optionals and had this working in Xcode 6 Beta 6, but to no avail in "Beta 7"

How do i get rid of this error? / Write a loop that goes through all my CollectionView Cells ?

like image 857
Ryan Avatar asked Sep 04 '14 09:09

Ryan


1 Answers

The collectionView property is now an optional UICollectionView?, so you have to unwrap it:

for cell in self.collectionView!.visibleCells() as [UICollectionViewCell] { ... }
like image 173
Martin R Avatar answered Nov 14 '22 22:11

Martin R