A lost link does not support a strong reference to itself, but makes the assumption that the object always has some value (it is not a nil), and if some of them are freed when the block is executed, the above code will work.
In the case of the weak, as in your example, the weak is an optional type inside the block, so there can also be a value, or it can be nil. You are responsible for checking if the value exists and call methods are called. As above, if you use the expand operator (!), When self has been freed, it will certainly work. Thus, both versions of the code fail if this happens so that the block is still executing, and self is freed up on average.
So, I suggest using weak to protect such failures, using additional checks,
{ [weak self] in if let me = self { me.number = me.number + 1 } }
source share