<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="">To extend on Keith’s explanation:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">class</span> C<T: Equatable> {</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">let</span> t: <span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">T</span>?</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">init</span>(t: <span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">T</span>?) { <span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">t</span> = t }</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class="">}</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177); min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">let</span> a = <span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">C</span><<span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">Int</span>>(t: <span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">nil</span>)</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(44, 158, 219);" class="">print<span style="font-variant-ligatures: no-common-ligatures; color: #a4b0b1" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">a</span><span style="font-variant-ligatures: no-common-ligatures; color: #a4b0b1" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">t</span><span style="font-variant-ligatures: no-common-ligatures; color: #a4b0b1" class="">)</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177); min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">let</span> b = <span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">C</span><<span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">Int</span>>(t: <span style="font-variant-ligatures: no-common-ligatures; color: #e5493d" class="">5</span>)</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(44, 158, 219);" class="">print<span style="font-variant-ligatures: no-common-ligatures; color: #a4b0b1" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">b</span><span style="font-variant-ligatures: no-common-ligatures; color: #a4b0b1" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">t</span><span style="font-variant-ligatures: no-common-ligatures; color: #a4b0b1" class="">)</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177); min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">let</span> c = <span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">C</span><<span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">Int</span>>(t: <span style="font-variant-ligatures: no-common-ligatures; color: #e5493d" class="">5</span>)</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(44, 158, 219);" class="">print<span style="font-variant-ligatures: no-common-ligatures; color: #a4b0b1" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">c</span><span style="font-variant-ligatures: no-common-ligatures; color: #a4b0b1" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">t</span><span style="font-variant-ligatures: no-common-ligatures; color: #a4b0b1" class="">)</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177); min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">func</span> ==(lhs: <span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">C</span><<span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">Int</span>>, rhs: <span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">C</span><<span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">Int</span>>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #7f87cf" class="">Bool</span> {</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">return</span> lhs.<span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">t</span> == rhs.<span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">t</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class="">}</div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177); min-height: 17px;" class=""><br class=""></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">var</span> d = <span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">a</span> <span style="font-variant-ligatures: no-common-ligatures; color: #2c9edb" class="">==</span> <span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">b<span class="Apple-tab-span" style="white-space:pre">        </span>// false</span></div><div style="margin: 0px; font-size: 16px; line-height: normal; font-family: Inconsolata; color: rgb(164, 176, 177);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #de5194" class="">var</span> e = <span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">b</span> <span style="font-variant-ligatures: no-common-ligatures; color: #2c9edb" class="">==</span> <span style="font-variant-ligatures: no-common-ligatures; color: #2fafa9" class="">c<span class="Apple-tab-span" style="white-space:pre">        </span>// true</span></div></div><div class=""><br class=""></div><div class="">You’d also need to override the “<font face="Inconsolata" size="3" class="">==</font>“ operator for <font size="3" face="Inconsolata" class="">C<Int></font> types in order to be able to compare them.</div><div class=""><br class=""></div><div class="">-Pete</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 29, 2016, at 10:07 AM, Keith Duvall 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Don’t mark it as optional in the generic definition. Mark it as optional in your implementation.<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> C<T: Equatable> {</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> t: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span>?</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">init</span>(t: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span>?) {</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">t</span> = t</div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> a = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>>(t: <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span>)</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">a</span><span style="" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">t</span><span style="" class="">) </span>// nil</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> b = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">C</span><<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>>(t: <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span>)</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">b</span><span style="" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">t</span><span style="" class="">) </span>// Optional(5)</div></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><font face="HelveticaNeue" class="">Keith</font></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On Feb 29, 2016, at 9:24 AM, Rudolf Adamkovič 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-size: 11px; font-family: Menlo;" class="">Hi everyone!</span></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">I have a generic class similar to this one:</span></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">class</span> C<T: Equatable> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> t: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">init</span>(t: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span>) { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">t</span> = t }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">When try to wrap ‘Int?' inside, I get the following error:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> a = C<<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>?>(t: <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span>) <span style="color: rgb(0, 132, 0);" class="">// ERROR: Type "Int?" does not conform to protocol 'Equatable'</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">Yet when I try to compare two ‘Int?’ values, everything works:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> a: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>? = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> b: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>? = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">6</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="color: rgb(187, 44, 162);" class="">let</span> c = <span style="color: rgb(79, 129, 135);" class="">a</span> == <span style="color: rgb(79, 129, 135);" class="">b</span><span style="color: rgb(79, 129, 135);" class=""> </span>// NO ERROR</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><div style="margin: 0px; line-height: normal; min-height: 13px;" class="">So, is ‘Int?' equatable or not?</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class="">Thanks!</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class="">R+</div></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=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div><br class=""></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=""></body></html>