Vin*_*van 10 xcode swift swift3 xcode8
我在类中有以下功能:
/// Returns the weather conditions at the given location.
/// - parameter for: A location on the Earth's surface.
/// - returns: If found, the `WeatherConditions` at the supplied location otherwise nil.
public func conditions(for location: Location) -> WeatherConditions? {
return nil // The actual code is not important to the question.
}
Run Code Online (Sandbox Code Playgroud)
这被称为如下let myWeather = conditions(for: myLocation).
代码工作正常,问题是关于文档.下图是该conditions功能的"快速帮助"窗口中显示的内容.假定函数的用户必须使用外部参数label(for),并且我已经明确记录了该标签,那么快速帮助窗口中的参数行是否应该读取Parameters for而不是Parameters location?
这是Xcode中的错误还是显示(内部)参数名称而不是外部参数标签的原因?
“for”一词不是强制词,它是可选的,以便在使用时更好地理解代码。
在 Swift 3 书中:
使用参数标签可以允许以富有表现力的、类似句子的方式调用函数,同时仍然提供可读且意图清晰的函数体。
如果没有这个词,编写代码将是
let myWeather = conditions(myLocation)
Run Code Online (Sandbox Code Playgroud)
当我们定义方法时,使用像 with:、using:、for:、withLabel: 等这样的词总是可以的。
| 归档时间: |
|
| 查看次数: |
670 次 |
| 最近记录: |