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?
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With