Re: Referring to self in property initializer

2015-08-17 Thread Fritz Anderson
On 14 Aug 2015, at 8:47 PM, Rick Mann rm...@latencyzero.com wrote: So, adding lazy lets it work with the closure (makes self available to the closure): lazy varbackgroundSession : NSURLSession= { ... I really wish you could do lazy let foo = I don't

Re: Referring to self in property initializer

2015-08-14 Thread Jens Alfke
On Aug 14, 2015, at 4:32 PM, Quincey Morris quinceymor...@rivergatesoftware.com wrote: No, there’s no instance here. “Enclosing” doesn’t really make any sense. It’s in the declaration of the ivar, I mean ‘stored property’, backgroundSession, so there is an instance. But I just realized

Re: Referring to self in property initializer

2015-08-14 Thread Jens Alfke
On Aug 14, 2015, at 4:24 PM, Rick Mann rm...@latencyzero.com 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

Referring to self in property initializer

2015-08-14 Thread Rick Mann
I'm having a hard time with this code: import Foundation class MyDelegate : NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDownloadDelegate { func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask,

Re: Referring to self in property initializer

2015-08-14 Thread Jens Alfke
On Aug 14, 2015, at 3:44 PM, Rick Mann rm...@latencyzero.com wrote: What is the type of self in the initializer closure, Wow, I didn’t even think you could use ‘self’ in such a context, since you’re not inside a method, just a closure. But it looks as though ‘self’ has type 'MyDelegate -

Re: Referring to self in property initializer

2015-08-14 Thread Quincey Morris
On Aug 14, 2015, at 15:44 , Rick Mann rm...@latencyzero.com wrote: What is the type of self in the initializer closure, It’s the class object itself, not an instance. and is there a way to refer to the enclosing class instance? No, there’s no instance here. “Enclosing” doesn’t really make

Re: Referring to self in property initializer

2015-08-14 Thread Rick Mann
On Aug 14, 2015, at 16:07 , Jens Alfke j...@mooseyard.com wrote: On Aug 14, 2015, at 3:44 PM, Rick Mann rm...@latencyzero.com wrote: What is the type of self in the initializer closure, Wow, I didn’t even think you could use ‘self’ in such a context, since you’re not inside a

Re: Referring to self in property initializer

2015-08-14 Thread Quincey Morris
On Aug 14, 2015, at 17:26 , Jens Alfke j...@mooseyard.com wrote: (Either way, it would still make sense for ‘self’ to be available.) Yes and no. Because it’s an ivar, the ivar’s value is associated with an instance rather than a class, but: — It’s being initialized by an arbitrary closure.

Re: Referring to self in property initializer

2015-08-14 Thread Rick Mann
So, adding lazy lets it work with the closure (makes self available to the closure): lazy varbackgroundSession : NSURLSession= { let config =