我正在学习和浏览Swift文档中的控制流部分。我遇到了一段我不理解的代码,我的问题是为什么在第5行,在where子句中,y的常量值被设置为负值。我的问题是为什么在第5行的where子句中,y的常量值被设置为负值。
let yetAnotherPoint = (1, -1)
switch yetAnotherPoint {
case let (x, y) where x == y:
print("(\(x), \(y)) is on the line x == y")
case let (x, y) where x == -y:
print("(\(x), \(y)) is on the line x == -y")
case let (x, y):
print("(\(x), \(y)) is just some arbitrary point")
}
// Prints "(1, -1) is on the line x == -y"