可以使用注释来书写不被执行的文档,用于注释或者来提醒你自己。注释会Xcode编译的时候被忽略。
Swift中得注释和C中非常相似,单行的注释以(//)开始:
// This is a comment
你也可以书写多行注释,以(/*)开始,并且以(*/)结尾:
- /* this is also a comment,
- but written over multiple lines */
不像C中得多行注释,在Swift中,多行注释是可以内嵌的,如下:
- /* 这是第一个多行注释
- /*这是第二个多行注释*/
- 这是第一个多行注释的结尾*/
例如:
- /* this is the start of the first multiline comment
- /* this is the second, nested multiline coovnent */
- this is the end of the first multiline comment */
内嵌注释可以使你能迅速和简单的注释掉大部分代码,即使代码已经包含了多行注释。