I understand the purpose of willset
and didset
my I am not sure if they are considered closures.
If they were closures, shouldn't the following code produce a strong reference cycle?
var myProperty : Int = 0 {
didSet { self.callMyMethod() }
}
No, they are not closures. You can think of it like a special type of function which is not directly accessible; it will only be called when the property changes. (The function is named myapp.MyStruct.myProperty.didset
; you can see this in the debugger.)