在房产内使用时,willSet
-didSet
和get
-set
之间有什么区别?
在我看来,它们都可以为属性设置值.什么时候,为什么,我应该使用willSet
-didSet
,什么时候使用get
-set
?
我知道对于willSet
和didSet
来说, struct 是这样的:
var variable1 : Int = 0 {
didSet {
println (variable1)
}
willSet(newValue) {
..
}
}
var variable2: Int {
get {
return variable2
}
set (newValue){
}
}