<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">2017-02-22 12:53 GMT+09:00 Ray Fix <span dir="ltr">&lt;<a href="mailto:rayfix@gmail.com" target="_blank">rayfix@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div><span class="gmail-"><blockquote type="cite"><div>On Feb 21, 2017, at 7:32 PM, rintaro ishizaki &lt;<a href="mailto:fs.output@gmail.com" target="_blank">fs.output@gmail.com</a>&gt; wrote:</div><br class="gmail-m_-285413739766435045Apple-interchange-newline"><div><div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-family:helvetica;font-size:12px">lifetime guaranteed to be around until the method call completes</span></blockquote><div><br></div><div>AFAIK, this is true.</div><div>However, in this case, it&#39;s not a method call. The lifetime is only guaranteed until <font face="monospace, monospace">getter:increment</font> completes.</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(79,129,135);font-variant-ligatures:no-common-ligatures">Demo</span><span style="font-variant-ligatures:no-common-ligatures">().</span><span style="color:rgb(79,129,135);font-variant-ligatures:no-common-ligatures">increment</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">3</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">|--------------| lifetime</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></div></div></div></blockquote><div><br></div></span><div><div>Thanks!  This is an interesting explanation.  </div><div><br></div><div>It is curious that naming the variable cases different behavior.</div><div>IOW, this doesn’t have a problem:</div><span class="gmail-"><div><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)"><br></span></div><div><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures"> demo = </span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Demo</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures">()</span></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">demo.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">increment</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">3</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div></div><div><br></div></span></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div><span class="gmail-"><div></div></span><div>Lifetime seems to last the entire expression. </div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div></font></span></div></div></div></blockquote><div><br class="gmail-Apple-interchange-newline">I&#39;m not sure, but I think the compiler is just lazy enough to release the &quot;<font face="monospace, monospace">demo&quot;</font> value <i>after</i> the entire expression or scope finishes.</div><div>Again, I&#39;m not sure. :)</div><div><br></div><div>Anyway, If I were you, I would define a wrapper method:</div><div><br></div><div><font face="monospace, monospace">class Demo {</font></div><div><font face="monospace, monospace">  var value = 0</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">  lazy var _increment: (Int) -&gt; Void { [unowned self] by in ... }<br>  func increment(by: Int) {</font></div><div><font face="monospace, monospace">    _increment(by)</font></div><div><font face="monospace, monospace">  }</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace">Demo().increment(by: 3)</font></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div><span class="gmail-HOEnZb"><font color="#888888"><div></div><div>Ray</div></font></span></div></div></div></blockquote></div><br></div></div>