DEV Community

Discussion on: When to use weak self and why

Collapse
 
gualtierofr profile image
Gualtiero Frigerio

I think this is a good explanation of weak self

I'd only mention this evolution introduced in 4.2
github.com/apple/swift-evolution/b...
so you can use
guard let self = self else { return }
instead of having strongSelf or another variable name in the closure.

Collapse
 
donnywals profile image
Donny Wals

Sounds like a good addition, I didn't add it to avoid confusion (self = self might look weird to folks who are learning about this stuff for the first time). Adding a separate callout might be nice though. Thanks!

Collapse
 
gualtierofr profile image
Gualtiero Frigerio

I guess for the purpose of an article strongSelf can be better as self = self may be confusing to some people as you say.
I've used strongSelf and weakSelf many times in Objective-C and I'm glad it is now possible to just use self in Swift now