Skip to content

Instantly share code, notes, and snippets.

@froggomad
Created June 18, 2021 16:21
Show Gist options
  • Save froggomad/523565a7d67b2d82376ab191d3952c15 to your computer and use it in GitHub Desktop.
Save froggomad/523565a7d67b2d82376ab191d3952c15 to your computer and use it in GitHub Desktop.
extension TitledCollectionView: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
produce?.count ?? 0
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ProduceCollectionViewCell.identifier, for: indexPath) as! ProduceCollectionViewCell
switch produce {
case .fruit:
cell.viewModel = Fruit.allCases[indexPath.item].viewModel
case .vegetable:
cell.viewModel = Vegetable.allCases[indexPath.item].viewModel
default: // handles optionality
break
}
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment