Swift 属性观察 略谈

来源:互联网 发布:movidius 知乎 编辑:程序博客网 时间:2024/09/21 09:28

/*********属性观察*******************/

class WangMumu {

var date: NSData {    willSet{        print("赋值前的值\(date)")        print("赋值后的值\(newValue)")    }    didSet{        print("赋值前的值\(oldValue)")        print("赋值后的值\(date)")    }}init(){    date = NSData()}

}

/*!
* set get willSet didSet 重写
*/

class A {

var number : Int {    get {        return 1    }    set {    }}

}

class B : A {

override var number: Int {    willSet{ }    didSet { }}

}

0 0
原创粉丝点击