我在这里找到了迭代枚举的优雅解决方案:
How to enumerate an enum with String type?
接下来,我无法弄清楚如何调用此方法.在面值,它看起来不像是一个参数,但当我尝试调用Card.createDeck()时,我得到一个编译错误告诉我“错误:在调用中缺少参数#1的参数”.
请让我知道我在这里做错了什么?我应该传递给这种方法的是什么?
struct Card { var rank: Rank var suit: Suit func simpleDescription() -> String { return "The \(rank.simpleDescription()) of \(suit.simpleDescription())" } func createDeck() -> [Card] { var deck = [Card]() var n = 1 while let rank = Rank.fromRaw(n) { var m = 1 while let suit = Suit.fromRaw(m) { deck += Card(rank: rank,suit: suit) m++ } n++ } return deck } }