swift 下划线的正式名称是什么?
What is the swift underscore's official name?
我最近一直在努力学习Swift特征的名称,以便我可以与使用这些名称的人交流。
例如
- 如果在类型名称的末尾添加
!
,则称为 "implicitly unwrapped optional type"
guard
表示"guard statement"
if let x = someOptional
被称为 "Optional binding"
case 0...9:
是switch语句中"pattern matching"的一个例子
但是有一项功能我不知道它的名字。
通常,我写这种代码是因为不推荐使用 C 风格的 for 循环:
for _ in 0...9 {
print("hello") //print hello 10 times
}
我想知道下划线叫什么
我知道这是来自Ruby。所以我认为它将与Ruby中的下划线同名。那么下划线到底叫什么?
我的猜测:
- 下划线运算符
- 下划线
- 下划线文字
- 下划线标识符
- 省略内容的下划线
这个有官方术语吗?如果没有,我将如何在关于我的代码的随意对话中称呼它?
它被称为通配符模式:
Wildcard Pattern
A wildcard pattern matches and ignores any value and consists of an underscore (_
). Use a wildcard pattern when you don’t care about the values being matched against. For example, the following code iterates through the closed range 1...3
, ignoring the current value of the range on each iteration of the loop:
for _ in 1...3 {
// Do something three times.
}
我最近一直在努力学习Swift特征的名称,以便我可以与使用这些名称的人交流。
例如
- 如果在类型名称的末尾添加
!
,则称为 "implicitly unwrapped optional type" guard
表示"guard statement"if let x = someOptional
被称为 "Optional binding"case 0...9:
是switch语句中"pattern matching"的一个例子
但是有一项功能我不知道它的名字。
通常,我写这种代码是因为不推荐使用 C 风格的 for 循环:
for _ in 0...9 {
print("hello") //print hello 10 times
}
我想知道下划线叫什么
我知道这是来自Ruby。所以我认为它将与Ruby中的下划线同名。那么下划线到底叫什么?
我的猜测:
- 下划线运算符
- 下划线
- 下划线文字
- 下划线标识符
- 省略内容的下划线
这个有官方术语吗?如果没有,我将如何在关于我的代码的随意对话中称呼它?
它被称为通配符模式:
Wildcard Pattern
A wildcard pattern matches and ignores any value and consists of an underscore (
_
). Use a wildcard pattern when you don’t care about the values being matched against. For example, the following code iterates through the closed range1...3
, ignoring the current value of the range on each iteration of the loop:for _ in 1...3 { // Do something three times. }