【发布时间】:2016-11-04 06:04:03
【问题描述】:
我知道如何使用 switch 语句提取枚举案例中的关联值:
enum Barcode {
case upc(Int, Int, Int, Int)
case quCode(String)
}
var productBarcode = Barcode.upc(8, 10, 15, 2)
switch productBarcode {
case let .upc(one, two, three, four):
print("upc: \(one, two, three, four)")
case .quCode(let productCode):
print("quCode \(productCode)")
}
但我想知道是否有办法使用元组提取关联值。
我试过了
let (first, second, third, fourth) = productBarcode
正如预期的那样,它没有用。有没有办法将枚举案例的关联值转换为元组?还是不可能?
【问题讨论】: