Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save froggomad/32822ae45152cc8172d1ee29d98245d6 to your computer and use it in GitHub Desktop.
Save froggomad/32822ae45152cc8172d1ee29d98245d6 to your computer and use it in GitHub Desktop.
extension TitledCollectionView: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
updateControllerDelegate(with: indexPath.item)
}
private func updateControllerDelegate(with item: Int) {
switch self.produce {
case .fruit:
let fruit = Fruit.allCases[item]
delegate?.itemWasSelected(fruit)
case .vegetable:
let vegetable = Vegetable.allCases[item]
delegate?.itemWasSelected(vegetable)
default: // nil value
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment