Swift Developer Challenge: Create a deck of cards

The deck-of-cards enumeration keeps coming up over and over again in #swift-lang because of the Swift Programming Language guided tour. I recently decided to create my own deck. I started on this because I wanted to test out some of GameplayKit features, namely shuffling, but also because I wanted to play a bit with CustomStringConvertible and CustomPlaygroundQuickLookable.

My goal was actually to build card views, shuffle a deck, and fan out the results. What I found was that the Unicode deck characters won’t render properly to UIKit contexts, where GameplayKit is freely available, and will to OS X ones, where GameplayKit isn’t. (I’m still primarily on Yosemite, not El Capitan.)

I filed some radars, created a post, and put my implementation to the side. Then Maximilian tweeted.

So here’s a developer challenge. Have at the deck enumeration, have some fun, and share your implementation on github. When you’re ready to peek, here’s mine.

One Comment

  • Hello Erica,
    One question: Can you really shrink
    ——————————-

    var description: String {
          switch self {
          case .Spades:
            return "♠️"
          case .Clubs:
            return "♣️"
          case .Diamonds:
            return "♦️"
          case .Hearts:
            return "♥️"
          }
    }

    ——————————-
    with:
    ——————————-

    var description: String {
            return ["♣️", "♦️", "❤️", "♠️"][rawValue - 1]
    }

    ——————————
    can you link some documentation?
    Thank you for your work and your books, they are precious.