Swift 5.7: is `guard let self` enough now?

1.7k Views Asked by At

I used to write stuff like this before Swift 5.7:

// random async completion block    
{ [weak self] in
    guard let weakSelf = self else { return }
    weakSelf.someString = ""
}

Now I would prefer writing this:

// random async completion block    
{ [weak self] in
    guard let self else { return }
    self.someString = ""
}

But can I do this without any issue, like retain cycles?

Thank you

1

There are 1 best solutions below

1
Jirson Tavera On

Yes it's, because the guard let self else & guard let weakSelf = self is the same thing

To avoid the retain cycle you are using weak, that's other thing