如何记录可选的闭包函数参数?

时间:2018-01-18 09:05:33

标签: swift xcode closures documentation 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
}

不会记录aClosureParameter。如何记录可选的闭包参数?

1 个答案:

答案 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
}

enter image description here