So, adding lazy lets it work with the closure (makes self available to the closure):
lazy var backgroundSession : NSURLSession = { let config = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier("com.matterport.StandaloneShowcase.ModelFetchConfiguration") let session = NSURLSession(configuration: config, delegate: self, delegateQueue: nil) return session }() Without lazy, you cannot initialize it with a call to a member (e.g. = self.createbackgroundSession()). You also cannot initialize it in init(), because of the restrictions on initializing and using self. This to me is one of the more cumbersome areas of the language. I really wish you could do lazy let foo = .... I don't see why the language can't support that. > On Aug 14, 2015, at 17:44 , Quincey Morris > <quinceymor...@rivergatesoftware.com> wrote: > > 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. There’s no particular > reason to regard the closure as associated with any specific instance. > > — It’s initializing an ivar. There’s no (accessible) ‘self’ object until all > of the class’s own ivars are initialized. Similarly, in an initializer, you > cannot assign ‘self’ to anything, until all ivars are initialized. So even if > ‘self’ was taken to mean “the” instance, it would still be an error. > > > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/rmann%40latencyzero.com > > This email sent to rm...@latencyzero.com -- Rick Mann rm...@latencyzero.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com