Closed. This question is opinion-based。它目前不接受答案。
想改进这个问题吗?更新问题,以便editing this post可以用事实和引用来回答。
6个月前关闭。
根据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)

有什么经验法则,或者我们应该遵循的最佳实践吗?所以,我们知道什么时候应该有参数标签,什么时候应该省略参数标签,什么时候来设计函数?

最佳答案

关于Swift中的命名,您应该查看API Design Guidelines。这些指导原则会让你对如何用Swift命名事物有一个大致的了解。不过,这是一个公平的警告,这些规则是相当理论性的,最后你要决定如何在特定情况下命名你的函数。不要太在意这个,即使是最有经验的开发人员也会遇到麻烦,所以我被告知。
在您的特定情况下,您绝对不应该省略参数标签,因为类型信息是非常通用的,并且不提供任何有关传入内容的线索。
希望这有帮助!

关于swift - 在Swift函数设计中何时应使用参数标签,何时应省略参数标签? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56155767/

10-09 09:14