Search code examples
iosswiftdocumentation-generation

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?


Solution

  • 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.