Jin*_*ong 5 documentation xcode closures swift swift4
你如何记录 Swift 4 中函数的可选闭包参数的参数?
假设您有一个将可选闭包作为参数的方法。例如,
/// An example function.
/// Documentation goes here.
///
/// - Parameters:
/// - optionalClosure: An optional closure.
/// - aClosureParameter: This will not be displayed.
func exampleMethod(optionalClosure: ((_ aClosureParameter: Bool) -> Void)?) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
不会记录 aClosureParameter。如何记录可选的闭包参数?
我无法判断这是故意的还是错误,但解决方法是使用Optional而不是声明参数类型?:
/// An example function.
/// Documentation goes here.
///
/// - Parameters:
/// - optionalClosure: An optional closure.
/// - aClosureParameter: This **will** be displayed.
func exampleMethod(optionalClosure: Optional<(_ aClosureParameter: Bool) -> Void>) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
667 次 |
| 最近记录: |