-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 {
}