Re: [swift-users] unowned self in closure in a playground

2017-02-21 Thread rintaro ishizaki via swift-users
2017-02-22 12:53 GMT+09:00 Ray Fix : > > On Feb 21, 2017, at 7:32 PM, rintaro ishizaki wrote: > > lifetime guaranteed to be around until the method call completes > > > AFAIK, this is true. > However, in this case, it's not a method call. The lifetime is only > guaranteed until getter:increment c

Re: [swift-users] unowned self in closure in a playground

2017-02-21 Thread Marco S Hyman via swift-users
>> > The problem with this solution is that this changes the semantics. I want a > value for every Demo instance. My error... I read too fast and missed the () instantiation of Demo in the failing call. I was reading it as Demo.increment(). Never mind. ___

Re: [swift-users] unowned self in closure in a playground

2017-02-21 Thread Ray Fix via swift-users
> On Feb 21, 2017, at 7:32 PM, rintaro ishizaki wrote: > > lifetime guaranteed to be around until the method call completes > > AFAIK, this is true. > However, in this case, it's not a method call. The lifetime is only > guaranteed until getter:increment completes. > > Demo().increment(3) > |

Re: [swift-users] unowned self in closure in a playground

2017-02-21 Thread Ray Fix via swift-users
Thanks. My comment below. > > On Feb 21, 2017, at 11:18 AM, Marco S Hyman wrote: > >> The following code crashes: >> >> class Demo { >> var value = 0 >> lazy var increment: (Int) -> Void = { [unowned self] by in >>self.value += by >>print(self.value) >> } >> } >> >> Demo().incremen

Re: [swift-users] unowned self in closure in a playground

2017-02-21 Thread rintaro ishizaki via swift-users
> > lifetime guaranteed to be around until the method call completes AFAIK, this is true. However, in this case, it's not a method call. The lifetime is only guaranteed until getter:increment completes. Demo().increment(3) |--| lifetime 2017-02-22 3:00 GMT+09:00 Ray Fix via swift-

Re: [swift-users] unowned self in closure in a playground

2017-02-21 Thread Zhao Xin via swift-users
I think you are right on ` lifetime guaranteed to be around until the method call completes`. But`[unowned self]` released the retain manually in your code. Just removing `[unowned self]` part, you code will work. Zhaoxin On Wed, Feb 22, 2017 at 3:18 AM, Marco S Hyman via swift-users < swift-user

Re: [swift-users] unowned self in closure in a playground

2017-02-21 Thread Marco S Hyman via swift-users
> The following code crashes: > > class Demo { > var value = 0 > lazy var increment: (Int) -> Void = { [unowned self] by in > self.value += by > print(self.value) > } > } > > Demo().increment(3) > error: Playground execution aborted: error: Execution was interrupted, > reason: EXC

[swift-users] unowned self in closure in a playground

2017-02-21 Thread Ray Fix via swift-users
Hi, The following code crashes: class Demo { var value = 0 lazy var increment: (Int) -> Void = { [unowned self] by in self.value += by print(self.value) } } Demo().increment(3) error: Playground execution aborted: error: Execution was interrupted, reason: EXC_BREAKPOINT (code=EXC