Implementing a deck of cards

So far, we have implemented a pretty generic app that lays out views inside a bigger view. Let's proceed to implement the foundation of the game: a deck of cards.

What we are expecting

Before implementing the classes for a deck of cards, we must define the behavior we are expecting, whereby we implement the calls in MemoryViewController, assuming that the Deck object already exists. First of all, we change the type in the definition of the property:

private var deck: Deck!

Then, we change the implementation of the start() function:

private func start() { deck = createDeck(numCardsNeededDifficulty(difficulty)) collectionView.reloadData() } private func createDeck(numCards: Int) -> Deck { let fullDeck = Deck.full().shuffled() ...

Get Swift 2 By Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.