Swift 2 Playground Comments with Markdown


One of the new features coming with Xcode 7 and Swift 2 playgrounds is the ability to use a variant of the markdown language to create richer comments more akin to documentation than standard comments.

Let’s take a look at how it works with the Beta 1 release

Standard code comments can take the form of a single or multiple lines (block) like these examples

    // A single line comment
    /*
    A block comment
    over two lines
    */

Now with Xcode 7 we can enhance the look and readability by simply adding a : to the comment line.

    //: _Rich text_ single line *comment* thanks to __Markdown__

To see how the text renders you need to go to the menu and choose Editor > Show Rendered Markup then you should get the following results in the playground.

Swift 2 Playground.playground

So far I have had mixed results with the block comment version so left it out of this example hoping that maybe it is just some early Beta issues. If you are not familiar with the markdown syntax then there are lots of resources on the Web to help you, personally I use it all the time and am very happy to see it making it’s way into Xcode.