相对比Java而言,Swift也提供了类似于Javadoc的内容。使用规定的注释语法来完成文档的撰写。但有点需要提及的是, Swift中的注释写法虽然能生成文档效果,但与Java的注解还是有区别的。
MARK:
该语法常用于文件结构。首字母要大写。
// MARK: - FUNC_ONE
private func displayContentOne(){
}
效果:
可以看到右侧预览区高亮FUNC_ONE。
TODO:
该语法常用于未完成功能的方法或类中。
// TODO: - Need to finish
private func displayContentTwo(){
}
(该语法在右侧无预览)
FIXME:
该语法用于提示标记或提示有问题的地方,例如为了测试而设立的一个临时变量。
// FIXME: - At here.
private func displayContentThree(){
}
(该语法在右侧无预览)
以上三种语法均可使用control + 6 来查看其文件结构。示例:
markdown:
常用于为他人撰写文档说明。
/**
*/
在第二行(空白行)内可撰写文档。
#空一格后跟一级标题,##空一格后跟二级标题,三级标题也是如此。如下所示:
/**
# This is test title.
## This is first 2rd title for test.
## This is second 2rd title for test.
*/
“***”用于分割线。可撰写多个分割线。
- important:空一格后跟重要描述
- returns:空一格后跟返回值
- parameter x:空一格后跟参数
全部示例:
/**
# This is test title.
## This is first 2rd title for test.
## This is second 2rd title for test.
***
Lines 1.
***
Lines 2.
***
- important: This is a method just for test. And in order to test this method we will make a long setences in here.
- returns: Void.
- parameter x: Just for test this method.
*/
private func displayContentFour(x: Int){
}
按下option + 鼠标左键,单击某个方法名,即可出现快捷帮助窗口,示例: