Swift 入門指南 V1.00 - 單元 2 範例




CH02.playground


var a = "Hello"
a = "Hi"
a = "Sorry"

var b = 1, c = 2, d = "中文字串"
println(b)
println(c)
println(d)

var f: String, i: Int, j:Bool
f = "There is no spoon."
i = 1
j = true

let e = 3.14
// e = 3.0

// array
var l = [1, 2, 3, 4, 5]
println(l[1])
l[1] = 78
println(l[1])

// dictionary
var m = ["1":"a", "2":"yes", "3":"no"]
println(m["3"])
m["3"] = "we"
println(m)
m["4"] = "after"
println(m)

var n = [1:"2", 2:"5", 5:"34"]
println(n[5])

// optional
var o: Int? = 1
// nil
o = nil

// tuple

var p = (12, "error", c:0.314)
println(p.1)
var q = (a:12, b:"error", c:0.314)
println(q.a)

// typealias
typealias NewInt = UInt16
println(NewInt.max)

the end

沒有留言: