As far as I know, you're doing the wrong casting.
Here are the changes I made to your code to make it work:
let first: Any = "One"
let second: Any = "Two"
let values = (first, second)
switch values {
case let (x as String, y as String):
print("Success", x, y)
default:
print("Failure")
}
switch first {
case let x as String:
print("Success", x)
default:
print("Failure")
}
Output:
Success One Two
Success One
Hope this helps!
source
share