<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I think you can achieve what you want by having the ‘defer’ block capture a mutable local variable. Eg,<div class=""><br class=""></div><div class="">func doStuff() {</div><div class=""> var success = false</div><div class=""><br class=""></div><div class=""> defer {</div><div class=""> if !success {</div><div class=""> // do some additional cleanup</div><div class=""> }</div><div class=""> }</div><div class=""><br class=""></div><div class=""> …</div><div class=""> success = true</div><div class=""> …</div><div class=""><br class=""></div><div class=""> return result</div><div class="">}<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 8, 2017, at 7:34 PM, Jun Zhang via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi dear swift developers,<div class=""> I am kind of new to swift and I don't know if this feature already exists. And if it exists already please tell me how. Thank you very much!</div><div class=""> The feature is to capturing the return value (maybe input value also) of the function. Here is the demo code:</div><div class=""><br class=""></div><div class=""><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);" class=""> <span style="color:rgb(194,52,155)" class="">func</span> tableView(<span style="color:rgb(194,52,155)" class="">_</span> tableView: <span style="color:rgb(0,175,202)" class="">UITableView</span>, numberOfRowsInSection section: <span style="color:rgb(0,175,202)" class="">Int</span>) -> <span style="color:rgb(0,175,202)" class="">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);" class=""> <span style="color:rgb(194,52,155)" class="">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);" class=""> <span style="color:rgb(194,52,155)" class="">if</span> $> >= <span style="color:rgb(139,132,207)" class="">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);" class=""><span style="color:rgb(255,255,255)" class=""> </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);" class=""> }</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);" class=""> <span style="color:rgb(194,52,155)" class="">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);" class=""><span style="color:rgb(255,255,255)" class=""> </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);" class=""> }</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);" class=""> }</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);" class=""> <span style="color:rgb(194,52,155)" class="">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);" class=""> }</div></div><div class=""><br class=""></div><div class=""> I suggest using `$>` as the return value symbol and `$<` as the input parameter symbol. </div><div class=""> Thank you all and best regards to you!</div></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></body></html>