Re: Referring to self in property initializer
Re: Referring to self in property initializer
- Subject: Re: Referring to self in property initializer
- From: Jens Alfke <email@hidden>
- Date: Fri, 14 Aug 2015 16:28:53 -0700
> On Aug 14, 2015, at 4:24 PM, Rick Mann <email@hidden> wrote:
>
> I really would've hoped that since the closure is defined within the scope of an instance of the class, that it would have a self made available to it. I've seen similar code that used "[unowned self] in" to use a weak reference.
Well, that code is different because ‘self’ is already a variable available in the local scope outside the block. In the case you’ve got, there is no local scope outside the block.
This seems like a reasonable feature to add to the language though — this kind of lazy ivar initializer is the moral equivalent of a method, so it should have ‘self’ available as a local. Especially since ’self’ is implicitly available already, i.e. you can already refer to local variables or call methods on self inside that block. File a Radar!
But yeah, as you said, the workaround would be to add a createBackgroundSession() method and make the lazy block call it.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden