Swift 函数参数标签的术语更改
Changes in terminology for Swift function parameter labels
Swift 提供了为函数参数提供内部和外部 name/label 的能力。但最近 Apple 似乎只使用 "Argument" 和 "Parameter" names/labels 而不再使用 internal/external 来描述这些东西。
在 Swift 文档和 WWDC 视频中,有一些不清楚的努力来描述函数的参数和参数之间的区别,而没有将它们称为面向外部或内部,such as:
Each function parameter has both an argument label and a parameter
name. The argument label is used when calling the function; each
argument is written in the function call with its argument label
before it. The parameter name is used in the implementation of the
function. By default, parameters use their parameter name as their
argument label.
想象一个 jump()
函数。
在内部,"when" 和 "height" 的名称可能不同,这些是内部名称。外部和内部似乎一点也不混淆,除了函数定义和声明中的顺序:
func jump(_ who: String, whenToJump when: Float, howHigh height: Int){
// wait for whenToJump
// adjust who.y by howHigh
)
Apple 指的是参数,哪个是参数?
所有内容都在本节中进行了详细描述
函数参数标签和参数名称
在The Swift Programming Language (Swift 3)
简而言之,Swift2和Swift3的区别是
- "External name" (Swift 2) 现在是 "Function Argument Label" (Swift 3)
- "Internal name" (Swift 2) 现在是 "Parameter Name" (Swift 3)
- 在(Swift 2)中第一个参数默认为
_ name
(内部,但没有外部)
- 在(Swift 3)中第一个参数默认为
name name
(函数参数标签和参数名称)。
Swift 提供了为函数参数提供内部和外部 name/label 的能力。但最近 Apple 似乎只使用 "Argument" 和 "Parameter" names/labels 而不再使用 internal/external 来描述这些东西。
在 Swift 文档和 WWDC 视频中,有一些不清楚的努力来描述函数的参数和参数之间的区别,而没有将它们称为面向外部或内部,such as:
Each function parameter has both an argument label and a parameter name. The argument label is used when calling the function; each argument is written in the function call with its argument label before it. The parameter name is used in the implementation of the function. By default, parameters use their parameter name as their argument label.
想象一个 jump()
函数。
在内部,"when" 和 "height" 的名称可能不同,这些是内部名称。外部和内部似乎一点也不混淆,除了函数定义和声明中的顺序:
func jump(_ who: String, whenToJump when: Float, howHigh height: Int){
// wait for whenToJump
// adjust who.y by howHigh
)
Apple 指的是参数,哪个是参数?
所有内容都在本节中进行了详细描述 函数参数标签和参数名称
在The Swift Programming Language (Swift 3)
简而言之,Swift2和Swift3的区别是
- "External name" (Swift 2) 现在是 "Function Argument Label" (Swift 3)
- "Internal name" (Swift 2) 现在是 "Parameter Name" (Swift 3)
- 在(Swift 2)中第一个参数默认为
_ name
(内部,但没有外部) - 在(Swift 3)中第一个参数默认为
name name
(函数参数标签和参数名称)。