Created
October 29, 2017 14:51
-
-
Save nathangitter/7c1958d274e01e30ead5a53c5b64f86c to your computer and use it in GitHub Desktop.
This file contains 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
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