swift - 无法理解为什么将常数 x 与 switch 案例中 where 子句中的负常数 y 进行比较
问题描述
我正在学习并浏览 Swift 文档中的控制流部分。我遇到了一大段我不明白的代码。我的问题是为什么在第 5 行, y 的常量值在 where 子句中设置为负数。
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"
解决方案
推荐阅读
- javascript - 在调试模式下,图像和视频未使用 axios 上传到服务器
- python - 实现后缀树
- node.js - codewithmosh NodeJS 课程几次要求我更改我的 NODE_ENV - 在 Windows 上不起作用?
- reactjs - 使用 Moment React 格式化日期
- python - 如何根据前一行合并数据框中的行?
- python - 如何仅替换第二次出现的 re.search() 组
- c# - 如何调整 ListBoxItems 的大小以适合容器?
- java - Spring @Qualifer 不与实现多个接口的 Bean 一起使用
- git - Git - 从分支的历史记录中删除文件
- android - 致命异常 android.view.InflateException:布局/activity_main 中的二进制 XML 文件行 #291:二进制 XML 文件行