Skip to content

Instantly share code, notes, and snippets.

@nathangitter
Created October 29, 2017 15:04
Show Gist options
  • Save nathangitter/0dfe218519cc0f71c2cb3d9297804375 to your computer and use it in GitHub Desktop.
Save nathangitter/0dfe218519cc0f71c2cb3d9297804375 to your computer and use it in GitHub Desktop.
extension ViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("selected item at \(indexPath)")
}
}
extension ViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return foods.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "food", for: indexPath) as? FoodCollectionViewCell
cell?.food = foods[indexPath.item]
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment