You still need to manually specify weak
and unowned
captures of self
. The only change SE-0269 results in is that you don't need to explicitly write out self.
when accessing instance properties/methods when acknowledging that you capture self
strongly by using [self]
.
In case of [weak self]
you still need to explicitly write self.
in the closure, but when using [unowned self]
, you can omit self.
just as when using [self]
.
execute { [weak self] in
x += 1 // Error: Reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit
}
execute { [weak self] in
self?.x += 1 // need to manually specify `self?.`
}
execute { [unowned self] in
x += 1 // compiles fine
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…