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: Developing iOS Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.