一.let(常量)
1)用途:用来声明常量
2)注意:
(1)只能赋值一次;
(2)声明的同时赋值,可以不加类型,但是只声明不赋值需要加类型(在变量后面声明类型,用冒号分割),如下:
let string:String
string = "23434"
(3)值永远不会被隐式转换为其他类型。如果需要把一个值转换成其他类型,需要显式转换,例如:
let string = "This width is"
let width = 14.0
let stirngWidth = string + String(width);
或者(值转换成字符串:把值写到括号中,并且在括号之前写一个反斜杠):
let someOne = 2
let call = "Hi,"
let name = "B."
let callName = call + "\(someOne)" + name
3)使用条件:决定一次,使用多次
二.var(变量)
1)用途:用来声明变量
2)用于可变数组、可变字典的声明和赋值,例如:
var array = ["1","2","3","4"]
var dic = ["Nmae":"Zhang","Sex":"Man"]