Search code examples
swiftxcodedocumentationmarkdownmarkup

What is the markup format for documentation on the parameters of a block in Swift?


The parameters of a block in Swift shows up with a table for parameters of the block if you add markup for documentation but I can not figure out how to fill out this table. I have searched for it in the Xcode markup reference formatting but I couldn't find anything on it.

Example:

/**
 Foo

 - parameter completion: A block to execute
 */
func foo(completion: (Bool) -> Void) {
    // do something
}

This is what shows up if I option + click in Xcode on the function above to view documentation:

Image of Xcode documentation view of a function

Apple's APIs show the completion block parameter table filled out. This is an example of a CloudKit API documentation view:

Image of Xcode documentation view of a function


Solution

  • You have to give a name to the parameter, but precede it with an underscore:

    /**
     Foo
    
     - parameter completion: A block to execute
     - parameter aflag: Some Bool flag
     */
    func foo(completion: (_ aflag: Bool) -> Void) {
        // do something
    }
    

    enter image description here