Swift编程基础入门
1. 注释
在Swift中,注释是不可执行的文本,可作为笔记或提醒。编译器会忽略注释内容。
- 单行注释:以两个斜杠(//)开头。
- 多行注释:以斜杠和星号(/ )开头,以星号和斜杠( /)结尾,且多行注释可以嵌套。
示例代码如下:
// This is a single-line comment.
/* This is a multiple-line
comment. */
/*
This is a comment.
/* This is also a comment, inside the first! */
Still a comment!
*/
此外,Playgrounds支持在注释中使用富文本标记,可定义标题、列表和引用,还能包含图像和链接。
2. 变量和常量
在Swift中,使用 let 或 var 关键字定义变量和常量:
- var :定义的变量值可以改变。
- let :定义的常量值不能改变,建议尽可能使用常量,因为更安全。
示例代码如下:
var myVariable = 123
let myConstantVariable = 123
myVariable += 5
// myConstantVaria
超级会员免费看
订阅专栏 解锁全文
3160

被折叠的 条评论
为什么被折叠?



