How to enumerate an enum with String type?
Asked 07 September, 2021
Viewed 2K times
  • 61
Votes
enum Suit: String {
    case spades = "♠"
    case hearts = "♥"
    case diamonds = "♦"
    case clubs = "♣"
}

For example, how can I do something like:

for suit in Suit {
    // do something with suit
    print(suit.rawValue)
}

Resulting example:

♠
♥
♦
♣

30 Answer