how to print the value of deck outside of Card struct?

  1. 12 months ago

    Hey guys? Please help. How can I print the values of deck outside the Card struct?

    enum Rank: Int {
    case Ace = 1
    case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten
    case Jack, Queen, King

    func simpleDescription() -> String {
    switch self {
    case .Ace:
    return "ace"
    case .Jack:
    return "jack"
    case .Queen:
    return "queen"
    case .King:
    return "king"
    default:
    return "Value"
    }
    }
    }

    enum Suit {
    case Spades, Hearts, Diamonds, Clubs

    func simpleDescription() -> String {
    switch self {
    case .Spades:
    return "spades"
    case .Hearts:
    return "hearts"
    case .Diamonds:
    return "diamonds"
    case .Clubs:
    return "clubs"
    }
    }
    }

    struct Card {
    var rank: Rank
    var suit: Suit
    func simpleDescription() -> String {
    return "The \(rank.simpleDescription()) of \(suit.simpleDescription())"
    }

    func createDeck() -> [Card] {
    let ranks = [Rank.Ace, Rank.Two, Rank.Three, Rank.Four, Rank.Five, Rank.Six, Rank.Seven, Rank.Eight, Rank.Nine, Rank.Ten, Rank.Jack, Rank.Queen, Rank.King]
    let suits = [Suit.Spades, Suit.Hearts, Suit.Diamonds, Suit.Clubs]
    var deck = [Card]()
    for suit in suits {
    for rank in ranks {
    deck.append(Card(rank: rank, suit: suit))
    }
    }
    return deck
    }
    }

or Sign Up to reply!