深色模式
Swift函数
外部参数名与内部参数名
Swift的函数,每个参数都有外部参数名(argument label)与内部参数名(parameter name),在调用函数时,要指定外部参数名,除非在定义函数时,忽略外部参数名。
函数参数名完整定义:
swift
func someFunction(argumentLabel parameterName: Int) {
// In the function body, parameterName refers to the argument value
// for that parameter.
}
someFunction(argumentLabel: 1)
如果不指定外部参数名,那么它默认与内部参数名相同:
swift
func someFunction(firstParameterName: Int, secondParameterName: Int) {
// In the function body, firstParameterName and secondParameterName
// refer to the argument values for the first and second parameters.
}
someFunction(firstParameterName: 1, secondParameterName: 2)
可手动忽略外部参数名:
swift
func someFunction(_ firstParameterName: Int, secondParameterName: Int) {
// In the function body, firstParameterName and secondParameterName
// refer to the argument values for the first and second parameters.
}
someFunction(1, secondParameterName: 2)