Set number of cells depending on array size <p>I'm a beginner and I want to change the number of cells in a collection view depending on whether the user would like to add more cells or not. I tried doing the same thing i did for table views but that doesn't seem to work. no matter what I change the size of the decks array to i only seem to be getting one cell on the screen.</p> <p>Here is my code :</p> <pre><code>class FlashViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { @IBOutlet var collectionView: UICollectionView! var decks = [5] override func viewDidLoad() { super.viewDidLoad() // Move on ... let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() layout.sectionInset = UIEdgeInsets(top: 75, left: 20, bottom: 10, right: 20) layout.itemSize = CGSize(width: 150, height: 200) collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout) self.collectionView.dataSource = self self.collectionView.delegate = self collectionView.registerClass(DeckCollectionViewCell.self, forCellWithReuseIdentifier: "DeckCollectionViewCell") collectionView.backgroundColor = UIColor.whiteColor() self.view.addSubview(collectionView!) } func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int { return self.decks.count } </code></pre>