百日学 Swift(Day 13) - Swift 复习 第 1 天

百日学 Swift(Day 13) - Swift 复习 第 1 天

1. Variables and constants - 变量和常量

  • 关键字 varlet
  • 名字必须唯一

2. Types of Data - 数据类型

  • String,Float, Double, Int,Bool
  • 显式声明,隐式声明(自动推断)

3. Operators - 操作符

  • 算术运算符,比较运算符……

4. String interpolation - 字符串插值

  • "The value is \(value)"

5. Arrays - 数组

  • 数组中的元素类型是一样的
  • 空数组一定要声明类型
  • 两个数组使用+合并为一个数组
  • 下标从 0 开始

6. Dictionaries - 字典

  • key: value
  • 一般 key 的类型为 String,当值的类型不确定或者不是一种时,可以使用 Any,
let dict: [String: Any] = ["id": 15, "name": "Swift"]

由于值的类型是 Any,所以使用时要注意返回的是可选项。

7. Conditional statements - 条件语句

  • if...else...
  • if...else if.. else...

8. Loops- 循环

  • a..<ba...b
  • for...in...
  • while...
  • continuebreak

9. Switch case - Switch 语句

switch 判定项 {
case 判定值1:
	语句
case 判定值2:
	语句
case 判定值3:
	语句
default:
    语句
}
发布了77 篇原创文章 · 获赞 16 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/hh680821/article/details/105186582