妹的!這貨竟然支持中文字符……雖然沒啥用,但我真是醉了……
變量:var
常量:let
0o
0b
ox
十進制的次冪:(以10爲底)
1 billion
1e-6
十六進制的次冪:(以2爲底)
十五的二次方:0xFp2
大數字:
十億元:1_000_000_000
元組:tuple
let skirt = (price:70, color:black, fit:true)
skirt.price
\() 括號內部可以填充整型、浮點型、字符串等數據類型用於組成字符串(挺好玩的)
Swift有類型推斷
unwrap $ binding
unwrap:
let str = "100"
str.toInt()
binding:
let bonus = 5_000_000
if var tempMoney = bonus
{
var afterTaxing = Double(tempMoney*0.8
println("Congratulations! You have got $\(tempMoney) dollars, after taxing is $\(afterTaxing)")
}
implicitly unwarpped optionals
assert(表達式,"說明")
索引超出、函數參數不符合、value必須是non-nil
一般用在調試過程中
取餘:%
可以對浮點數取餘……
for循環:
for xxx in 1...100 // 閉區間
for xxx in 1..<100 // 開區間
函數:func
可以有多個返回值
eg:
func getNums()->(Int, Int){ return(2,3) }
let (a,b) = getNums();
允許將函數名定義爲變量
eg:
var numAB = getNums()
numAB("ZhangSan")
函數閉包:在函數內部創建函數。
類:
重載:override func funcName(){}
構造:init(){}