willSet didSet
class EatBaBa {
var who="musi"{
willSet{
}
didSet{
self.who="musi"
}
}
var much=1000{
didSet(newValue){
self.much = 100000
}
}
var what:String{
set{
}
get{
return "\(self.who) eat \(self.much) 坨屎"
}
}
}
var eat=EatBaBa();
eat.who="lingyi"
eat.much=0
print(eat.what)
输出结果
musi eat 100000 坨屎