<div dir="ltr">Yes that&#39;s true, but this requires me to set a return value in every `early return` statement. I think this should be done by the compiler instead of me, to make code cleaner and also less error-prone.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 9, 2017 at 11:24 AM, Slava Pestov <span dir="ltr">&lt;<a href="mailto:spestov@apple.com" target="_blank">spestov@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">I think you can achieve what you want by having the ‘defer’ block capture a mutable local variable. Eg,<div><br></div><div>func doStuff() {</div><div>  var success = false</div><div><br></div><div>  defer {</div><div>    if !success {</div><div>      // do some additional cleanup</div><div>    }</div><div>  }</div><div><br></div><div>  …</div><div>  success = true</div><div>  …</div><div><br></div><div>  return result</div><div>}<br><div><br><blockquote type="cite"><div><div class="h5"><div>On Oct 8, 2017, at 7:34 PM, Jun Zhang via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br class="m_-185679576177401347Apple-interchange-newline"></div></div><div><div><div class="h5"><div dir="ltr">Hi dear swift developers,<div>   I am kind of new to swift and I don&#39;t know if this feature already exists. And if it exists already please tell me how. Thank you very much!</div><div>  The feature is to capturing the return value (maybe input value also) of the function. Here is the demo code:</div><div><br></div><div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(255,255,255);background-color:rgb(40,43,53)">    <span style="color:rgb(194,52,155)">func</span> tableView(<span style="color:rgb(194,52,155)">_</span> tableView: <span style="color:rgb(0,175,202)"><wbr>UITableView</span>, numberOfRowsInSection section: <span style="color:rgb(0,175,202)">Int</span>) -&gt; <span style="color:rgb(0,175,202)">Int</span> {</div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(255,255,255);background-color:rgb(40,43,53)">        <span style="color:rgb(194,52,155)">defer</span> {</div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(255,255,255);background-color:rgb(40,43,53)">            <span style="color:rgb(194,52,155)">if</span> $&gt; &gt;= <span style="color:rgb(139,132,207)">0</span> {</div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(77,191,86);background-color:rgb(40,43,53)"><span style="color:rgb(255,255,255)">                </span>// table is not empty</div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(255,255,255);background-color:rgb(40,43,53)">            }</div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(255,255,255);background-color:rgb(40,43,53)">            <span style="color:rgb(194,52,155)">else</span> {</div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(77,191,86);background-color:rgb(40,43,53)"><span style="color:rgb(255,255,255)">                </span>// table is empty</div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(255,255,255);background-color:rgb(40,43,53)">            }</div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(255,255,255);background-color:rgb(40,43,53)">        }</div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(255,255,255);background-color:rgb(40,43,53)">        <span style="color:rgb(194,52,155)">return</span> dataSource.cout</div><div style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Consolas;color:rgb(255,255,255);background-color:rgb(40,43,53)">    }</div></div><div><br></div><div>   I suggest using `$&gt;` as the return value symbol and `$&lt;` as the input parameter symbol. </div><div>   Thank you all and best regards to you!</div></div></div></div>
______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>