Are you sick and forgot to count closures in Swift?

I understand the purpose willsetand didsetmy, I'm not sure that they are considered closure.

If they were closures, shouldn't the following code generate a strong reference loop?

var myProperty : Int = 0 {
    didSet { self.callMyMethod() }
}
+4
source share
1 answer

No, they are not closed. You can think of it as a special type of function that is not directly accessible; it will be called only when the property changes. (The function is called myapp.MyStruct.myProperty.didset, you can see it in the debugger.)

+4
source

Source: https://habr.com/ru/post/1599226/


All Articles