I\'m trying to use a tuple as an optional binding in an IF statement in Swift but it won\'t compile and that error message is less than helpful. Why doesn\'t the following
Let's say we have tuple having two optional Ints. To unwrap it we can optionally cast it to (Int, Int) using as?. If any of them is nil then it won't be able to cast it. If it does we will get unwrapped values from that tuple.
let tuple: (Int?, Int?) = (1, 2)
if let (value1, value2) = tuple as? (Int, Int) {
print("value1: \(value1), value2: \(value2)")
}
//value1: 1, value2: 2