<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello everybody,<div class=""><br class=""></div><div class="">This is my first request or suggestion, so don’t really know if this is the format you are looking for. I’ve been searching lately to build the perfect API for a soon to be open source project.</div><div class=""><br class=""></div><div class="">Such project has a different set of functions that have different views as parameters, based on the number of views, the closure that the function will give back to you will have different arguments, (one view returns one argument in the closure). After putting a variadic argument I wanted to do the same for closures since the API reads much nicer and I don’t have to duplicate code to cover all the cases.</div><div class=""><br class=""></div><div class="">From a code point of view it makes sense that it behaves like that, you have a variadic parameter and inside the function it behaves as an array, the same way, you have different variadic parameters in the closure and inside such implementation you have an array. Even though this is nice, I think the best case scenario to not have to repeat code would be to parse in the compiler in a smart way, meaning, if the argument is a variadic component, then $0 will be the first argument of the variadic array, $1 the second one and so on.</div><div class=""><br class=""></div><div class="">This way API’s like:</div><div class=""><br class=""></div><div class=""><a href="https://github.com/robb/Cartography/blob/master/Cartography/Constrain.swift" class="">https://github.com/robb/Cartography/blob/master/Cartography/Constrain.swift</a></div><div class=""><br class=""></div><div class="">Could be simplified into just one method with variadic functions without having the user to deal with an array in their end.</div><div class=""><br class=""></div><div class="">Going to attach a bit of code from the Apple documentation, retouched a bit:&nbsp;<a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html" class="">https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html</a></div><div class=""><br class=""></div><div class="">```</div><div class=""><ol class="code-lines" style="border: 0px; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; counter-reset: li 0; line-height: 1.6em; list-style: none; font-family: Helvetica, Arial, sans-serif;"><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"><span class="kt" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">func</span> <span class="vc" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">divideTwo</span>(<span class="vc" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">numbers</span>: <span class="n" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span>…, solutions: (Double…) -&gt; Void) {</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;">  <span class="kt" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">results</span>:<font color="#5c2699" class=""> [Double]</font> = <font color="#1c00cf" class="">[]</font></code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;">  <span class="kt" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">for</span> <span class="vc" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">number</span> <span class="kt" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">in</span> <span class="vc" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">numbers</span> {</code></li><ol class=""><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;">results.append(number / 2)</code></li></ol><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;">  }</code></li></ol><div style="text-indent: -13px;" class=""><font face="Menlo, monospace" class=""><span style="white-space: pre-wrap;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span></font></div><div style="text-indent: -13px;" class=""><font face="Menlo, monospace" class="">&nbsp; &nbsp; solutions(results)</font></div><ol class="code-lines" style="border: 0px; font-size: 14px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; counter-reset: li 0; line-height: 1.6em; list-style: none; font-family: Helvetica, Arial, sans-serif;"><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;">}</code></li></ol><div style="text-indent: -13px;" class=""><font face="Menlo, monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div><div style="text-indent: -13px;" class=""><font face="Menlo, monospace" class=""><span style="white-space: pre-wrap;" class="">&nbsp; // In their end.</span></font></div><div style="text-indent: -13px;" class=""><font face="Menlo, monospace" class=""><span style="white-space: pre-wrap;" class="">&nbsp;</span></font></div><div style="text-indent: -13px;" class=""><font face="Menlo, monospace" class=""><span style="white-space: pre-wrap;" class="">  divideTwo(2, 4) {</span></font></div><div style="text-indent: -13px;" class=""><font face="Menlo, monospace" class=""><span style="white-space: pre-wrap;" class="">&nbsp;   print($0)</span></font></div><div style="text-indent: -13px;" class=""><font face="Menlo, monospace" class=""><span style="white-space: pre-wrap;" class="">    print($1)</span></font></div><div style="text-indent: -13px;" class=""><font face="Menlo, monospace" class=""><span style="white-space: pre-wrap;" class="">  }</span></font></div><div style="text-indent: -13px;" class=""><span style="text-indent: 0px;" class="">```</span></div><div style="text-indent: -13px;" class=""><font face="Menlo, monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div><div style="text-indent: 0px;" class="">This would only behave like this in the case where a variadic argument is given back as a parameter in the closure.</div><div class=""><br class=""></div></div></body></html>