Another approach would be to simply allow<br><br>guard let self = self else { return }<br><div class="gmail_quote"><div dir="ltr">On Sat, Dec 5, 2015 at 3:48 AM Robert Vojta <<a href="mailto:rvojta@me.com">rvojta@me.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
let’s say we have a completion handler closure for some function (networking, …) and we have [weak self] there. Example …<br>
<br>
doSomething() { [weak self] result in<br>
…<br>
}<br>
<br>
… then we can use self?.whatever to access self properties, methods. Or we can try to check if self exists ...<br>
<br>
guard let strongSelf = self else { return }<br>
<br>
… and use strongSelf.<br>
<br>
Can we introduce [weakStrong self] with following behavior:<br>
<br>
- self is a weak reference<br>
- when the closure is going to be executed, all weakStrong weak references are checked if they do exist<br>
- if they do exist, they’re strong referenced for the closure and the closure is executed<br>
- if they don’t exist, closure is not executed<br>
<br>
doSomething() { [weakStrong self] result in<br>
// Closure code is not executed if self no longer exists<br>
// self is a strong reference now<br>
}<br>
<br>
What do you think? Does it make sense?<br>
<br>
My motivation is to get rid off of the repetitive code like this one:<br>
<br>
doSomething() { [weak self] result in<br>
guard let strongSelf = self else { return }<br>
strongSelf.doSomethingWithResult(result)<br>
}<br>
<br>
Robert<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>