You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know most of our projects typically separate out table/collection view functionality into separate objects. We should take this a step further and make some generic controllers to handle this (which I think some projects already do). Since SwiftUI is coming (eventually), we shouldn't spend too much time on it, but at least handling the basic case of presenting a list of identical cells should be a goal.
I spent a few minutes doodling so here's something to get started:
classCollectionController<ItemType,CellType:UICollectionViewCell>:NSObject,UICollectionViewDataSource{privateletitems:[ItemType]privateletcellConfigurationBlock:(ItemType,CellType)->Voidinit(items:[ItemType], cellConfigurationBlock:@escaping(ItemType,CellType)->Void){self.items = items
self.cellConfigurationBlock = cellConfigurationBlock
}func collectionView(_ collectionView:UICollectionView, numberOfItemsInSection section:Int)->Int{return items.count
}func collectionView(_ collectionView:UICollectionView, cellForItemAt indexPath:IndexPath)->UICollectionViewCell{
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier:String(describing:CellType.self), for: indexPath)as?CellTypeelse{fatalError("Unable to dequeue cell of type '\(CellType.self)'")}letitem=items[indexPath.item]cellConfigurationBlock(item, cell)return cell
}}
The text was updated successfully, but these errors were encountered:
I know most of our projects typically separate out table/collection view functionality into separate objects. We should take this a step further and make some generic controllers to handle this (which I think some projects already do). Since SwiftUI is coming (eventually), we shouldn't spend too much time on it, but at least handling the basic case of presenting a list of identical cells should be a goal.
I spent a few minutes doodling so here's something to get started:
The text was updated successfully, but these errors were encountered: