Swift注释写法

相对比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 + 鼠标左键,单击某个方法名,即可出现快捷帮助窗口,示例:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值