<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="">Whilst implementing XCTests for NSKeyedUnarchiver, I noticed some issues with equality.</div><div class="">Let’s say I have the following simple Swift program:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">import</span> SwiftFoundation</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> url1 = NSURL(string: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"foo.xml"</span>, relativeToURL:NSURL(string: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"<a href="https://www.example.com" class="">https://www.example.com</a>"</span>))!</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> url2 = NSURL(string: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"foo.xml"</span>, relativeToURL:NSURL(string: <span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"<a href="https://www.example.com" class="">https://www.example.com</a>"</span>))!</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; print(<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"</span>\<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">(</span>url1.isEqual(url2)<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">)"</span>)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; print(<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"</span>\<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">(</span>url1 == url2<span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">)"</span>)</div></div><div class=""><br class=""></div><div class="">It returns false for both, as opposed to true on OS X Foundation.</div><div class=""><br class=""></div><div class="">NSObject() implements Equatable in terms of isEqual; that’s fine, but apart from __NSCFType the bridged types do not implement isEqual:. It seems that hash, isEqual and description need to be pasted in for the bridged types, à la CF_CLASSIMPLEMENTATION.</div><div class=""><br class=""></div><div class="">I feel though I may be missing something – I would have thought TestFoundation would depend on the equality operator working :)</div><div class=""><br class=""></div>— Luke</body></html>