-2
我可以比较没有关联值的关联枚举大小写吗?请检查下面的代码片段如何比较没有关联值的关联枚举
//Declare associated enum
enum Example
{
case test(x:Int)
case test1(x:String)
}
//Creating enum with associated value
let testWithAssociatedValue = Example.test(x:0)
if case .test = testWithAssociatedValue { //WorksFine
}
//Now having enum with no associated value
let testWithNoAssociatedValue = Example.test
Now Why comparing enum that has no associated value like below,gives me compile error?.
if case .test = testWithNoAssociatedValue {
}