Headerdoc with delegate Protocols - Swift and xcode 7.2

377 views Asked by At

I have defined a protocol and added HeaderDoc documentation to the method in this protocol. It appears correctly when I Option+Click the method:

Image of documentation in the protocol

However, when I Option+Click the implementation within a controller that implements this protocol, the documentation is not showing up:

enter image description here

My expectation is that the documentation I wrote for the protocol would show up in the controller, similar to the documentation from Apple:

enter image description here

How do I get my protocol documentation to be visible elsewhere?

1

There are 1 answers

2
AudioBubble On BEST ANSWER

If you document the protocol's method implementation within a protocol extension, the documentation will then be visible within any type that conforms to the protocol.

If you omit the extension's documentation, the canDo documentation from the protocol doesn't show up anywhere else but the protocol itself, as you noticed.

protocol Doable {
    /// Does something
    func canDo()
}

extension Doable {
    /// Does something really well
    func canDo() {
        print("Did it!")
    }
}

struct Task: Doable {
    init() {
        canDo()
    }
}

enter image description here