How can you set a property\'s value in Swift, without calling its didSet()
function outside of an initialization context? The code below was a failed experimen
If you exactly know when you want to apply side effects just make it explicitly:
1 Solution:
func noside(newValue : Int) {
hoodwink = newValue
}
func withside(newValue : Int) {
self.hoodwink = newValue
toggle = !toggle
}
2 Solution:
var toggle : Bool = false
var hoodwink : Int = 0
var hoodwinkToggle: Int {
get { return hoodwink }
set(newValue) {
hoodwink = newValue
toggle = !toggle
}
}
I think these solutions will be more clear and readable, then using one variable which at some calls should have side effects and shouldn't at others.