<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="">Wow! Thanks for (extra-extra-extra) detailed answer. I will try this.<div class=""><br class=""></div><div class="">R+<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 29 Feb 2016, at 17:41, <a href="mailto:davesweeris@mac.com" class="">davesweeris@mac.com</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 class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">To the best of my understanding, </span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">Int</span><span style="" class=""><font face="Menlo" class="">?</font> is not equatable. Your </span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(187, 44, 162);">let</span><span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;" class=""> </span><span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;" class="">c =</span><span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;" class=""> </span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">a</span><span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;" class=""> </span><span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;" class="">==</span><span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;" class=""> </span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">b</span> code works because this function (or something like it) is defined:</div></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> == <T: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Equatable</span><span style="font-variant-ligatures: no-common-ligatures" class="">> (lhs: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Optional</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">>, rhs: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Optional</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">>) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (lhs, rhs) {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (.None, .None): </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">true</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (.Some(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> l), .Some(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> r)): </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> l </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">==</span><span style="font-variant-ligatures: no-common-ligatures" class=""> r</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">default</span><span style="" class="">: </span><span style="font-variant-ligatures: no-common-ligatures" class="">return</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">false</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div style="margin: 0px; line-height: normal;" class="">The reason it’s done this way is that currently there’s no mechanism for conditional protocol conformance. Ideally, you’d be able to write something like this:</div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Optional</span><span style="font-variant-ligatures: no-common-ligatures" class=""> : </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Equatable</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span><span style="font-variant-ligatures: no-common-ligatures" class=""> T: Equatable {}</span></div><div style="margin: 0px; line-height: normal;" class="">… which, combined with that existing <span style="font-family: Menlo;" class="">==</span> function, would make <span style="color: rgb(112, 61, 170); font-variant-ligatures: no-common-ligatures;" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">?</span> be equatable.</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">IIRC, Apple is intending to remove this limitation, but I can’t remember if it’s made the cut for Swift 3 or if it’ll be later on.</div></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">In the meantime, if Keith’s solution of making the variable be a <span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">T</span><span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures;" class="">?</span> instead of <span style="font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">T</span> doesn’t work for you, I <i class="">think</i> this will let you continue on with other parts of your code (although I have NOT thoroughly tested it… use at your own risk):</div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> OptionalWrapper<T> : </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Equatable</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">typealias</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Wrapped = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> unwrap: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Wrapped</span><span style="font-variant-ligatures: no-common-ligatures" class="">?</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class=""> value: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Wrapped</span><span style="font-variant-ligatures: no-common-ligatures" class="">?) { </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">unwrap</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = value }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> == <T: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Equatable</span><span style="font-variant-ligatures: no-common-ligatures" class="">> (lhs: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">OptionalWrapper</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">>, rhs: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">OptionalWrapper</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">>) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (lhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">unwrap</span><span style="font-variant-ligatures: no-common-ligatures" class="">, rhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">unwrap</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (.None, .None): </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">true</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (.Some(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> l), .Some(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> r)): </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> l </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">==</span><span style="font-variant-ligatures: no-common-ligatures" class=""> r</span></div><div style="margin: 0px; line-height: normal; color: rgb(187, 44, 162);" class=""><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">default</span><span style="" class="">: </span><span style="font-variant-ligatures: no-common-ligatures" class="">return</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">false</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> == <T: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Equatable</span><span style="font-variant-ligatures: no-common-ligatures" class="">> (lhs: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">OptionalWrapper</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">?>, rhs: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">OptionalWrapper</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">?>) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (lhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">unwrap</span><span style="font-variant-ligatures: no-common-ligatures" class="">, rhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">unwrap</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (.None, .None): </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">true</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (.Some(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> l), .Some(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> r)): </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> l == r</span></div><div style="margin: 0px; line-height: normal; color: rgb(187, 44, 162);" class=""><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">default</span><span style="" class="">: </span><span style="font-variant-ligatures: no-common-ligatures" class="">return</span><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">false</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> == <T> (lhs: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">OptionalWrapper</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">>, rhs: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">OptionalWrapper</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">>) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (lhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">unwrap</span><span style="font-variant-ligatures: no-common-ligatures" class="">, rhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">unwrap</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (.None, .None): </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">true</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (.Some, .None): </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">false</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (.None, .Some): </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">false</span></div><div style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);" class=""><span style="" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="" class=""> (.Some, .Some): </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">fatalError</span><span style="" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"</span><span style="" class="">\</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">__FILE__</span><span style="font-variant-ligatures: no-common-ligatures" class="">):</span><span style="" class="">\</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">__LINE__</span><span style="font-variant-ligatures: no-common-ligatures" class="">):</span><span style="" class="">\</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">__COLUMN__</span><span style="font-variant-ligatures: no-common-ligatures" class="">): Binary operator '==' cannot be applied to two '</span><span style="" class="">\</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span><span style="" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">)' operands"</span><span style="" class="">)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div class=""><br class=""></div></div></div><div style="margin: 0px; line-height: normal;" class="">The syntax for actually using it is a bit long, but it should work: </div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="" class=""> a = </span><span style="font-variant-ligatures: no-common-ligatures" class="">C</span><span style="" class="">(t: </span><span style="font-variant-ligatures: no-common-ligatures" class="">OptionalWrapper</span><span style="" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">4</span><span style="" class="">)) </span><span style="color: rgb(0, 132, 0);" class="">// infers that Wrapped == Int</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="" class=""> b = </span><span style="font-variant-ligatures: no-common-ligatures" class="">C</span><span style="" class="">(t: </span><span style="font-variant-ligatures: no-common-ligatures" class="">OptionalWrapper</span><span style="" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="" class="">>(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span><span style="" class="">)) </span><span style="color: rgb(0, 132, 0);" class="">// must be explicit since nil is just Optional.None, without any other type info</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> c = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">a</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">t</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">==</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">b</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">t</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 132, 0);" class="">// false</span><span style="font-variant-ligatures: no-common-ligatures" class=""></span></div><div class=""><br class=""></div><div class="">Hope that helps</div><div class=""><br class=""></div></div><div style="margin: 0px; line-height: normal;" class="">- Dave Sweeris</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 29, 2016, at 8: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></blockquote></div><br class=""></div></div></body></html>