Fast enumeration through UICollectionView cells - Swift

I try to quickly list all the cells in the collection, but this implementation below gives me a warning.

for cell in self.collectionView?.visibleCells() as [UICollectionViewCell] { // Do Stuff } 

The first line shows the error below:

Postfix operand '?' must be of an optional type; type '(UICollectionView, cellForItemAtIndexPath: NSIndexPath) -> UICollectionViewCell

I tried communicating with options and worked in Xcode 6 Beta 6, but to no avail in "Beta 7"

How can I get rid of this error? / Write a loop that goes through all my CollectionView cells?

+5
source share
1 answer

Now is the collectionView property an optional UICollectionView? , so you have to expand it:

 for cell in self.collectionView!.visibleCells() as [UICollectionViewCell] { ... } 
+9
source

Source: https://habr.com/ru/post/1201802/


All Articles