我有一个这样的枚举
enum TheType {
case a (CustomData)
case b (NSDictionary)
case c (String?)
case d
case e
...
}
在一个特定的地方,我只是想判断类型是否为b,然而在咨询了几个关于if和case的教程并try 了几种排列之后,我仍然无法编译它,这是最新的try 变体:
let theType = TheType.b([:])
if case let TheType.b(_) == theType {...}
产生错误: ‘_’只能出现在赋值左侧的模式中
或者,这会产生一个不同的错误:
if case let TheType.b(let theDictionary) == theType {...}
交换对象以使Type位于==的左侧也会产生错误.
如何使用If语句判断枚举值的类型?