I know how to extract associated values in enum cases using switch statement:
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)")
}
But I was wondering if there is a way to extract associated value using tuples.
I tried
let (first, second, third, fourth) = productBarcode
As expected, it did not work. Is there a way to turn associated value of enum cases into a tuple? or it is not possible?