How to compare enum with associated values by ignoring its associated value in Swift?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: After reading How to test equality of Swift enums with associated values , I implemented the following enum: enum CardRank { case Number(Int) case Jack case Queen case King case Ace } func ==(a: CardRank, b: CardRank) -> Bool { switch (a, b) { case (.Number(let a), .Number(let b)) where a == b: return true case (.Jack, .Jack): return true case (.Queen, .Queen): return true case (.King, .King): return true case (.Ace, .Ace): return true default: return false } } The following code works: let card: CardRank = CardRank.Jack if card == CardRank