Skip to content

Instantly share code, notes, and snippets.

@nathangitter
Created October 29, 2017 14:51
Show Gist options
  • Save nathangitter/7c1958d274e01e30ead5a53c5b64f86c to your computer and use it in GitHub Desktop.
Save nathangitter/7c1958d274e01e30ead5a53c5b64f86c to your computer and use it in GitHub Desktop.
class MyViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
var foods = ["🍎", "🍌", "🍓"]
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("selected item at \(indexPath)")
}
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