Re: [swift-users] lazy initialisation

2016-07-09 Thread Karl via swift-users
> On 9 Jul 2016, at 06:34, Zhao Xin wrote: > > The compiler is not smart enough to treat this as you think, nor it will be > designed to. According to the documents, it is the developer‘s burden ​to add > @noescape or weak or unowned. So I disagree it is a bug. > > Zhaoxin > > On Sat, Jul 9,

Re: [swift-users] lazy initialisation

2016-07-08 Thread Zhao Xin via swift-users
The compiler is not smart enough to treat this as you think, nor it will be designed to. According to the documents, it is the developer‘s burden ​to add @noescape or weak or unowned. So I disagree it is a bug. Zhaoxin On Sat, Jul 9, 2016 at 7:30 AM, Karl wrote: > > On 5 Jul 2016, at 03:47, Zha

Re: [swift-users] lazy initialisation

2016-07-08 Thread Karl via swift-users
> On 5 Jul 2016, at 03:47, Zhao Xin wrote: > > No, it is not a bug. > > For a closure, you have to call self explicitly unless the closure is mark as > @noescape. Also, in this situation, self is not unowned, as the closure is > not stored, it ran and released. Below, is a situation that you

Re: [swift-users] lazy initialisation

2016-07-04 Thread Zhao Xin via swift-users
No, it is not a bug. For a closure, you have to call self explicitly unless the closure is mark as @noescape. Also, in this situation, self is not unowned, as the closure is not stored, it ran and released. Below, is a situation that you need use unowned self. Here the closure is stored in variabl

Re: [swift-users] lazy initialisation

2016-07-04 Thread Karl via swift-users
> On 4 Jul 2016, at 21:12, Mark Dalrymple via swift-users > 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, >

Re: [swift-users] lazy initialisation

2016-07-04 Thread J.E. Schotsman via swift-users
> On 04 Jul 2016, at 21:12, Mark Dalrymple wrote: > > lazy var c:Int = {return self.a * self.b}() > > It's in a closure, so need to explicitly reference self. Oh of course, I got tripped up by the similarity of TestStruct1 and TestStruct2. Problem solved. BTW this compiles:

Re: [swift-users] lazy initialisation

2016-07-04 Thread Mark Dalrymple via swift-users
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 On Mon, Jul 4, 2016 at 3:04 PM, J.E. Schotsman via swift-users < swift-users@swift.org>

Re: [swift-users] lazy initialisation

2016-07-04 Thread J.E. Schotsman via swift-users
> On 04 Jul 2016, at 19:21, Zhao Xin wrote: > > You'd better sharing some of you code here first. For example, consider this: class TestStruct1 { let a = 10 let b = 20 let c:Int = {return self.a*self.b}() } Of course this is a trivial example. In reali

Re: [swift-users] lazy initialisation

2016-07-04 Thread Mark Dalrymple via swift-users
This works for me class Blorg: NSObject, URLSessionDelegate { var config: URLSessionConfiguration lazy var session: URLSession = { print("howdy") return URLSession(configuration: self.config, delegate: self, delegateQueue: nil) }() override init() {

Re: [swift-users] lazy initialisation

2016-07-04 Thread Zhao Xin via swift-users
You'd better sharing some of you code here first. Zhaoxin On Tue, Jul 5, 2016 at 1:04 AM, J.E. Schotsman via swift-users < swift-users@swift.org> wrote: > Hello, > > I need to initialize a variable of a class with a closure using the value > of some variables of the class. > Since this is not pe

[swift-users] lazy initialisation

2016-07-04 Thread J.E. Schotsman via swift-users
Hello, I need to initialize a variable of a class with a closure using the value of some variables of the class. Since this is not permitted I thought I might solve the problem by declaring it lazy. But this is still rejected by the compiler. If there are no circular dependencies in initializati