someFunction(completion: { [weak self] in
self?.variable = self!.otherVariable
})
Is this always safe? I access the optional <
Is this always safe
No. You are not doing the "weak-strong dance". Do it! Whenever you use weak self
, you should unwrap the Optional safely, and then refer only to the result of that unwrapping — like this:
someFunction(completion: { [weak self] in
if let sself = self { // safe unwrap
// now refer only to `sself` here
sself.variable = sself.otherVariable
// ... and so on ...
}
})