Playground中格式注释语法

时间:2023-03-08 23:59:48
Playground中格式注释语法

类似于Ruby的ruby document,Xcode的Playground自身也提供一些嵌入文档中的格式注释的语法.

我们先定义一个简单的类:

class A{

}

按住opt点击class A,你会发现啥都没有

Playground中格式注释语法

我们在class A上面增加一行注释,只不过有别于单行注释的//,我们用的是///

///A simple class that does some stuff you want it to do

Playground中格式注释语法

现在描述具体多了吧.

接下来我们在类中添加一个方法:

///Does something;in this case ,prints out a message letting the user know that something is hanppening
    func test(){
        print(#function)
    }

我们同样用///来描述该方法:

Playground中格式注释语法

上面的方法没有参数和返回值,下面是一个签名齐全方法的实例:

/**
        this method is make two people to super couple!!!but be careful not everyone can make super successed,and even make successd,that's no one can give word that result is good!

        - Parameter name: the first person's name
        - Parameter otherName: the second person's name,aka other person ;]��
        - Returns: A combined couple name

    */
    func makeSuper(name:String,otherName:String)->String{
        let str = "\(name) combine with \(otherName) to super couple!!!"
        print(str)
        return str
    }

Playground中格式注释语法

如果方法有多个参数,我们嫌写多个Parameter麻烦,我们也可以用以下的语法,效果是一样的:

- Parameters:
            - name: the first person's name
            - otherName: the second person's name,aka other person ;]��
        - Returns: A combined couple name

Xcode还提供其他的注释分类:

- Author: Panda Hopy
        - Version: 1.04
        - Note: This is a simple class
        - Warning: This class doesn't actually do anything!
        - ToDo: Add some actual functionality to this class

效果如下:

Playground中格式注释语法

如果我们喜欢,我们可以进一步美化格式,比如增加标题,粗体,斜体以及有序和无序列表:

# Lists
        You can apply *italic* , **bold** , or `code` inline styles to any text ,and _what_

        ## Unordered Lists
        - Some item
        - Another item
        - The last item

        ## Ordered Lists
        1. Some item
        2. Another item
        3. The last item

Playground中格式注释语法

更详细的注释语法,我们可以到apple开发网站查询:

https://developer.apple.com/library/ios/documentation/Xcode/Reference/xcode_markup_formatting_ref/AnyPage.html#//apple_ref/doc/uid/TP40016497-CH22-SW1