[swift-evolution] Wanted: syntactic sugar for [weak self] callbacks

Kurt Werle kurt at circlew.org
Tue Feb 2 02:31:49 CST 2016


The bind thread is certainly similar, and if something like that was
adapted, I'd like to see [bind self] do the same kind of thing in closure
declarations that I'm proposing [firm self] does - but the very odd []
syntax for closure parameters tastes pretty different to me than a lot of
the rest of the language.  I don't think it's unreasonable to discuss them
separately.

Thanks,
Kurt

On Tue, Feb 2, 2016 at 12:02 AM, Félix Cloutier <felixcca at yahoo.ca> wrote:

> Hi Kurt,
>
> I believe that this is currently being discussed in "the bind thread
> <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160201/008649.html>
> ".
>
> Félix
>
> Le 1 févr. 2016 à 18:40:18, Kurt Werle via swift-evolution <
> swift-evolution at swift.org> a écrit :
>
> The pattern
>
> someObject.callBack() { [weak self] in
>   if let me = self {
>     me.doSomething()
>     ...
>   }
> }
>
> and friends (guard, etc) are pretty common.  I'd love to have some sugar
> for that - maybe "firm"
>
> someObject.callBack() { [firm self] in
>   self.doSomething()
>   ...
> }
>
> where firm guarantees that the named variable[s] won't be nil - if they
> are, the block is skipped.
>
> I think this would make the language easier to use (skipping the
> complexities/distinction between weak/unowned), more concise, and generally
> more pleasant.
>
> Thoughts?
>
> Thanks,
> Kurt
> --
> kurt at CircleW.org <kurt at circlew.org>
> http://www.CircleW.org/kurt/ <http://www.circlew.org/kurt/>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
>


-- 
kurt at CircleW.org
http://www.CircleW.org/kurt/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160202/057df0eb/attachment.html>


More information about the swift-evolution mailing list