Pitch: Syntactic sugar for circumventing closure capture lists

Just to reiterate, this obviously works when self is used inside bar:
self.foo = { [weak self] in self?.bar($0) }

This is so unswifty, especially when building libraries for consumption. It forces me to make consumers use delegates instead which I don't want to do. I just want consumers to do this:
self.foo = self.bar

The implicit strong reference is no good for these cases, but I imagine would wreak havoc for existing code out there if Swift changed this behind the scenes to implicit weak.

Something like this would be nice:
self.foo = @unowned(self).bar

Or maybe:
@weak func bar() {...}

Apologies for bumping this old thread, but there are tons of dead end discussions about this and is a really rough area in Swift.

5 Likes