<div><div dir="auto">This feature request is probably one for swift evolution.</div><div dir="auto"><br></div><div dir="auto">I like the idea in theory, but I’d prefer to see the return value identifier being spelled out, i.e. “returnValue” instead of the symbols.</div><br><div class="gmail_quote"><div dir="auto">Jun Zhang via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> schrieb am Mo. 9. Okt. 2017 um 05:37:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Yes that'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><<a href="mailto:spestov@apple.com" target="_blank">spestov@apple.com</a>></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="m_-1158594090887244331h5"><div>On Oct 8, 2017, at 7:34 PM, Jun Zhang via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div><br class="m_-1158594090887244331m_-185679576177401347Apple-interchange-newline"></div></div><div><div><div class="m_-1158594090887244331h5"><div>Hi dear swift developers,<div> 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> 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)">UITableView</span>, numberOfRowsInSection section: <span style="color:rgb(0,175,202)">Int</span>) -> <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> $> >= <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 `$>` as the return value symbol and `$<` as the input parameter symbol.</div></div></div></div></div></blockquote></div></div></div></blockquote></div></div></blockquote><div dir="auto"><br></div><div dir="auto">Also, I’m not sure what “input parameter” means here.</div><div dir="auto"><br></div><div dir="auto">Geordie</div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><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"><div><div><blockquote type="cite"><div><div><div class="m_-1158594090887244331h5"><div><div></div><div> Thank you all and best regards to you!</div></div></div></div>
_______________________________________________<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/mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>
_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div></div>