Swift 常见语法错误
Swift 常见语法错误
- 无效的重复声明
1 | let (_, errMsg) = httpError |
- 强制类型
1 | var notFountError = (404, "Not Found Error") |
- 类型推导 & 可选类型
1 | var catchphrase: String? |
- 语法错误,for-in 语句
1 | for index 1...5 { |
- immutable collection 不可变
1 | let immutableArray: [String] = ["a1", "a2"] |
- 类型推导 & 可选类型
1 | var mutatingDic = ["name": "yuntianming", "age": "29"] |
- 方法只有在单执行语句时,才不需要
return
关键字
1 | func multipyExp(x: Int,y: Int) -> Int { |
- 函数参数位置问题
1 | func addx1(x :Int,y :Int) -> Int { |
- Final Class 不可被继承
1 | final class Child: Person {} |
- 构造器参数标注丢失
1 | class ios: ModeOfTransportation { |
- 空集合字面量生成时,明确类型
1 | let array = [] |
- Let 定义常量不可变
1 | let age = 10 |