swift 方法参数语法
swift with syntax on method parameters
我在代码示例和博客中看到过这种语法,但没有看到它的解释:
func exampleFunc(arg1: String, withOtherArgument otherArgument: String) -> Void {}
with 语法有什么作用?为什么有必要,它与 just 有何不同:
func exampleFunc(arg1: String, otherArgument: String) -> Void {}
正如 Apple 的 documentation 所说:
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.
在您的第一个示例中,withOtherArgument
是参数标签,otherArgument
是参数名称。
我在代码示例和博客中看到过这种语法,但没有看到它的解释:
func exampleFunc(arg1: String, withOtherArgument otherArgument: String) -> Void {}
with 语法有什么作用?为什么有必要,它与 just 有何不同:
func exampleFunc(arg1: String, otherArgument: String) -> Void {}
正如 Apple 的 documentation 所说:
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.
在您的第一个示例中,withOtherArgument
是参数标签,otherArgument
是参数名称。