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




CH13.playground


class CClass {
    var name: String
    
    init(name: String) {
        self.name = name
        println("\(name) is being initialized")
    }
    
    deinit {
        println("\(name) is being deinitialized")
    }
}

// 三個 CClass 的選擇型態
var demo1: CClass?
var demo2: CClass?
var demo3: CClass?

// 三個選擇型態都指向 Tony
demo1 = CClass(name: "Tony")
demo2 = demo1
demo3 = demo1

// 兩個選擇型態指向 nil
demo1 = nil
demo2 = nil

demo1
demo2
demo3

var t1 = ["a":"1", "b":"2"]
t1["a"]

var t2 = "0"
t2.append(Character(t1["a"]!))
t2

the end

沒有留言: