Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document optional closure function parameters?

Tags:

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?

like image 638
Jinyeong Avatar asked Jan 18 '18 09:01

Jinyeong


1 Answers

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

like image 99
Martin R Avatar answered Sep 20 '22 13:09

Martin R