<分区>
根据 https://docs.swift.org/swift-book/LanguageGuide/Functions.html
我们可以将函数设计为
带有参数标签
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)
或者
省略参数标签
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, 2)
是否有任何我们应该遵循的经验法则或最佳实践?这样,我们就知道在设计函数时什么时候应该有参数标签,什么时候应该省略参数标签?