<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">In the code below, I'm trying to store a reference to a function with any number of arguments, with any return type. And I want to be able to invoke it.&nbsp;<div class=""><br class=""></div><div class="">Help?<div class=""><br class=""></div><div class="">See the comments with "<span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 14px; background-color: rgb(255, 255, 255);" class="">*******"</span></div><div class=""><font color="#008400" face="Menlo" class=""><span style="font-size: 14px; background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">typealias</span> Void = ()</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">func</span> equalTypes(<span style="color: #ba2da2" class="">_</span> me: [<span style="color: #ba2da2" class="">Any</span>.Type], <span style="color: #ba2da2" class="">_</span> other: [<span style="color: #ba2da2" class="">Any</span>.Type]) -&gt; <span style="color: #703daa" class="">Bool</span> {</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">guard</span> me.<span style="color: #703daa" class="">count</span> == other.<span style="color: #703daa" class="">count</span> <span style="color: #ba2da2" class="">else</span> { <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">false</span> }</div><p style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 16px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">for</span> i <span style="color: #ba2da2" class="">in</span> <span style="color: #272ad8" class="">0</span> ..&lt; me.<span style="color: #703daa" class="">count</span> {</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">if</span> me[i] != other[i] { <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">false</span> }</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; </span>return<span style="color: #000000" class=""> </span>true</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">struct</span> Function {</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">var</span> returnType: <span style="color: #ba2da2" class="">Any</span>.Type</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">var</span> argTypes: [<span style="color: #ba2da2" class="">Any</span>.Type]</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; </span><span style="color: #ba2da2" class="">var</span><span style="color: #000000" class=""> function: </span><span style="color: #ba2da2" class="">Any</span><span style="color: #000000" class=""> </span>// ******* any function *******</div><p style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 16px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">func</span> perform(<span style="color: #ba2da2" class="">_</span> args: [<span style="color: #ba2da2" class="">Any</span>]) -&gt; <span style="color: #ba2da2" class="">Any</span> {</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// ******* call function() with args, return result *******</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">return</span> <span style="color: #272ad8" class="">0</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 16px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">func</span> isCompatible(<span style="color: #ba2da2" class="">_</span> other: <span style="color: #4f8187" class="">Function</span>) -&gt; <span style="color: #703daa" class="">Bool</span> {</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">self</span>.<span style="color: #4f8187" class="">returnType</span> == other.<span style="color: #4f8187" class="">returnType</span> &amp;&amp;</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #31595d" class="">equalTypes</span>(<span style="color: #4f8187" class="">argTypes</span>, other.<span style="color: #4f8187" class="">argTypes</span>)</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">func</span> vToV() {</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; </span><span style="color: #3e1e81" class="">print</span><span style="color: #000000" class="">(</span>"vToV"<span style="color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">func</span> intToInt(<span style="color: #ba2da2" class="">_</span> i: <span style="color: #703daa" class="">Int</span>) -&gt; <span style="color: #703daa" class="">Int</span> {</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; </span><span style="color: #3e1e81" class="">print</span><span style="color: #000000" class="">(</span>"intToInt"<span style="color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; </span>return<span style="color: #000000" class=""> </span><span style="color: #272ad8" class="">4</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> f = <span style="color: #4f8187" class="">Function</span>(returnType: <span style="color: #4f8187" class="">Void</span>.<span style="color: #ba2da2" class="">self</span>,</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; argTypes: [],</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function: <span style="color: #31595d" class="">vToV</span>)</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> r = <span style="color: #4f8187" class="">f</span>.<span style="color: #31595d" class="">perform</span>([])</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class="">print<span style="color: #000000" class="">(</span><span style="color: #4f8187" class="">r</span><span style="color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> f2 = <span style="color: #4f8187" class="">Function</span>(returnType: <span style="color: #703daa" class="">Int</span>.<span style="color: #ba2da2" class="">self</span>,</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; argTypes: [<span style="color: #703daa" class="">Int</span>.<span style="color: #ba2da2" class="">self</span>],</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function: <span style="color: #31595d" class="">intToInt</span>)</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span> r2 = <span style="color: #4f8187" class="">f2</span>.<span style="color: #31595d" class="">perform</span>([<span style="color: #272ad8" class="">12</span>])</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class="">print<span style="color: #000000" class="">(</span><span style="color: #4f8187" class="">r2</span><span style="color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);" class=""><span style="color: #3e1e81" class="">assert</span><span style="color: #000000" class="">(</span><span style="color: #4f8187" class="">f</span><span style="color: #000000" class="">.</span>isCompatible<span style="color: #000000" class="">(</span><span style="color: #4f8187" class="">f</span><span style="color: #000000" class="">))</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);" class=""><span style="color: #3e1e81" class="">assert</span><span style="color: #000000" class="">(!</span><span style="color: #4f8187" class="">f</span><span style="color: #000000" class="">.</span>isCompatible<span style="color: #000000" class="">(</span><span style="color: #4f8187" class="">f2</span><span style="color: #000000" class="">))</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Helvetica; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">--<br class="">C. Keith Ray<br class="">Senior Software Engineer / Trainer / Agile Coach<br class="">* <a href="http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf" class="">http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf</a><br class=""></div><div style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div></div><br class="Apple-interchange-newline">
</div>

<br class=""></div></div></body></html>