[swift-users] lazy initialisation

Karl razielim at gmail.com
Mon Jul 4 14:42:57 CDT 2016


> On 4 Jul 2016, at 21:12, Mark Dalrymple via swift-users <swift-users at swift.org> wrote:
> 
> Here's the one I started with:
> 
>    lazy var c:Int = {return a*b}()
> 
> and ended up with:
> 
>     lazy var c:Int = {return self.a * self.b}()
> 
> It's in a closure, so need to explicitly reference self.
> 
> Cheers,
> ++md
> 


I’ve been hitting this myself. I think it’s a bug -- yes, you are technically in a closure, but the closure does not capture ‘self’ beyond the lifetime of ‘self’. In this context, ’self’ should automatically be ‘unowned’.

Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160704/b073024a/attachment.html>


More information about the swift-users mailing list