如何在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
}
不会记录aClosureParameter。如何记录可选的闭包参数?
答案 0 :(得分:2)
我不知道这是故意还是错误,但是解决方法是
使用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
}