Created
June 18, 2021 16:21
-
-
Save froggomad/523565a7d67b2d82376ab191d3952c15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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