Abdullah
Abdullah

Reputation: 7233

Swift documentation comment @code equivalent.

I am aware about Swift documentation comment and many of its tags that are used to document code like :param:, :return: etc.

But I am not able to find or figure out @code Objective-C documentation comment equivalent for Swift. I want to include some code example in the description of some class in my open source project but I am not sure how to do that.

Could anyone please shed some light on how to do that or that is even possible at this stage?

Upvotes: 3

Views: 434

Answers (2)

James Webster
James Webster

Reputation: 32066

Using appledoc, you just need to indent your code 4 spaces

/*!
Documentation for the class.

Here is a code sample

    func code()
    {
        //code
    }
*/

You'll notice that a lot of the formatting options are similar to Stack Overflow! They both use Markdown for formatting.

I just happen to have documented a project using appledoc for the first time so I have a few of the pages in recent history. The code feature is documented here


Regarding your question about :code: @code syntax options. Appledoc directives accept any non-whitespace-character followed by a keyword. To Xcode, documenation is just a comment.

Directives prefix: Although all directives in examples above use "@" sign as a prefix, you can actually use any non-whitespace char instead, for example \param, $param, %param and so on...

[Source]

It does seem however, that the common @code isn't supported by appledoc the way it is by other documentation tools like doxygen.

Upvotes: 4

Mrugesh Tank
Mrugesh Tank

Reputation: 3560

as per the reference of here you can write documentation for code block as per below.

/**
    The area of the `Shape` instance.

    Computation depends on the shape of the instance. For a triangle, `area` will be equivalent to:

      let height = triangle.calculateHeight()
      let area = triangle.base * height / 2
*/
var area: CGFloat { get }

Upvotes: 1

Related Questions