您的位置:首页 > 其它

Playground中格式注释语法

2016-08-26 07:58 127 查看
类似于Ruby的ruby document,Xcode的Playground自身也提供一些嵌入文档中的格式注释的语法.

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

class A{

}


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



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

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




现在描述具体多了吧.

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

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


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



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

/**
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
}




如果方法有多个参数,我们嫌写多个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


效果如下:



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

# 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




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

https://developer.apple.com/library/ios/documentation/Xcode/Reference/xcode_markup_formatting_ref/AnyPage.html#//apple_ref/doc/uid/TP40016497-CH22-SW1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: