1

I'm implementing Apple's example of using enums to create a Card struct, but the simpleDescription() method doesn't work. Apple suggests:

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

but when I call

let card = Card(rank: .queen, suit: .hearts)
print("card = \(Card(rank: .queen, suit: .hearts))")

the console prints out

card = Card(rank: twoMatch.Rank.queen, suit: twoMatch.Suit.hearts)

where "twoMatch" is the name of my app, and ignores the string I've constructed in simpleDescription(). I've checked the method signature several times and have even copied it over from the examples in Rank and Suit, which work just fine.

hkatz
  • 951
  • 11
  • 21

1 Answers1

1

You're defining the wrong method. That's just some arbitrary name in one of Apple's samples. Check this out instead:

What is the Swift equivalent of -[NSObject description]?

Fernando Mazzon
  • 3,562
  • 1
  • 19
  • 21