在以下代码中需要帮助。
let first: Any = "One"
let second: Any = "Two"
let values = (first, second)
switch values {
case let (x, y) as (String, String):
print("Success", x, y)
default:
print("Failure")
}
switch first {
case let x as String:
print("Success", x)
default:
print("Failure")
}
---输出
Failure
Success One
---预期输出
Success One Two
Success One
答案 0 :(得分:4)
据我所知,你做错了。
以下是我对您的代码所做的更改,以便它可以正常运行:
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")
}
<强>输出:强>
Success One Two
Success One
希望这有帮助!