Jinyeong
Jinyeong

Reputation: 53

How to document optional closure function parameters?

How do you document the parameters of a function's optional closure parameter in Swift 4?

Let's say that you have a method that takes an optional closure as a parameter. For example,

/// 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
}

The aClosureParameter would not be documented. How to document the optional closure parameters?

Upvotes: 5

Views: 783

Answers (1)

Martin R
Martin R

Reputation: 539815

I cannot tell if that is intentional or a bug, but a workaround is to declare the parameter type using Optional instead of ?:

/// 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

Upvotes: 4

Related Questions