Updated Code : Swift 4.2/Swift 5
enum Suit: String, CaseIterable {
case spades = "?"
case hearts = "?"
case diamonds = "?"
case clubs = "?"
}
To access the Output as per question:
for suitKey in Suit.allCases {
print(suitKey.rawValue)
}
Output :
?
?
?
?
CaseIterable:
provides a collection of all of its values.
Types that conform to the CaseIterable protocol are typically enumerations without associated values. When using a CaseIterable type, you can access a collection of all of the type’s cases by using the type’s allCases property.
For accessing cases we are using .allCases. For more information click https://developer.apple.com/documentation/swift/caseiterable