<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=""><div class="">Thanks for all the information. This was a cross-post from Stack Overflow:</div><div class=""><br class=""></div><div class=""><a href="http://stackoverflow.com/questions/36061561/generic-factory-method-and-type-inference" class="">http://stackoverflow.com/questions/36061561/generic-factory-method-and-type-inference</a></div><div class=""><br class=""></div><div class="">If you are a Stack Overflow user, you can copy the answer there and I will accept it as correct.</div><div class=""><br class=""></div><div class="">Either way, thanks for the explanation!</div><div class=""><br class=""></div><div class="">R+</div><br class=""><div><blockquote type="cite" class=""><div class="">On 17 Mar 2016, at 16:51, Brent Royal-Gordon &lt;<a href="mailto:brent@architechies.com" class="">brent@architechies.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><blockquote type="cite" class="">final class Something&lt;T&gt; {<br class=""><br class=""> &nbsp;&nbsp;&nbsp;let value: T<br class=""><br class=""> &nbsp;&nbsp;&nbsp;init(initial: T) {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value = initial<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""><br class="">}<br class=""><br class="">extension Something {<br class=""><br class=""> &nbsp;&nbsp;&nbsp;class func zip&lt;A, B&gt;(a: A, _ b: B) -&gt; Something&lt;(A, B)&gt; {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let initial = (a, b)<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return Something&lt;(A, B)&gt;(initial: initial)<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""><br class="">}<br class=""><br class="">How come I can’t call zip without explicitly specifying return type?<br class=""><br class="">// ERROR: Cannot invoke `zip` with an argument list of type `(Int, Int)`<br class="">let y = Something.zip(1, 2)<br class=""><br class="">// OK: Works but it’s unacceptable to require this on caller's side<br class="">let x = Something&lt;(Int, Int)&gt;.zip(1, 2)<br class=""></blockquote><br class="">The reason you're seeing this is that there's nothing in this call:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let y = Something.zip(1, 2)<br class=""><br class="">That tells Swift what `T` should be. The return type of the `zip` method is not connected to T; you can actually put any random type in the angle brackets after Something:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let y = Something&lt;UICollectionViewDelegateFlowLayout&gt;.zip(1, 2)<br class=""><br class="">Unfortunately, Swift doesn't currently have the features needed to properly connect `T` to the return type. If the language were more sophisticated, you could say something like this:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>extension&lt;A, B&gt; Something where T == (A, B) {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;&nbsp;&nbsp;class func zip(a: A, _ b: B) -&gt; Something {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let initial = (a, b)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return Something(initial: initial)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;&nbsp;&nbsp;}<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><br class="">But for now, you'll have to make do with this horrible hack, which works by meaninglessly reusing the T type parameter:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>extension Something {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;&nbsp;&nbsp;class func zip&lt;B&gt;(a: T, _ b: B) -&gt; Something&lt;(T, B)&gt; {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let initial = (a, b)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return Something&lt;(T, B)&gt;(initial: initial)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;&nbsp;&nbsp;}<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><br class="">Hope this helps,<br class="">-- <br class="">Brent Royal-Gordon<br class="">Architechies<br class=""><br class=""></div></div></blockquote></div><br class=""></body></html>