<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="">NSObject’s hash (which Set uses) is done via&nbsp;ObjectIdentifier, which IIRC uses something along the lines of the object's address. That’s why you’re getting the behavior you’re seeing.<div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); 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; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha</div>

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Mar 28, 2017, at 20:20, Zhao Xin via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default"><font face="georgia, serif" class="">Turns out that for `NSObject`, protocol `Equatable` wasn't used. Instead, it used `NSObjectProtocol.isEqual(_ object: Any?)`. Also, override `func isEqual(_ object: Any?) -&gt; Bool` requires to override `var hash: Int { get }` as well.</font></div><div class="gmail_default"><font face="georgia, serif" class=""><br class=""></font></div><div class="gmail_default"><font face="georgia, serif" class="">I think this behavior should be mentioned in Swift docs or manual in `Set` section.</font></div><div class="gmail_default"><font face="georgia, serif" class=""><br class=""></font></div><div class="gmail_default"><font face="georgia, serif" class="">Below code works.&nbsp;</font></div><div class="gmail_default"><font face="georgia, serif" class=""><br class=""></font></div><div class="gmail_default"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">class</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Bar:</span><span style="font-variant-ligatures:no-common-ligatures" class="">NSObject</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">override</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> hashValue: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class=""> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">return</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="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">static</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> ==(lhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">, rhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Bool</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> lhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> == rhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures" class="">// required by NSObjectProtocol</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">override</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> isEqual(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class=""> object: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">Any</span><span style="font-variant-ligatures:no-common-ligatures" class="">?) -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Bool</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">if</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> rhs = object </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">as</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="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</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=""> rhs</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures" class="">false</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures" class="">override</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> hash: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> { </span><span style="font-variant-ligatures:no-common-ligatures" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures" class="">self</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="">hashValue</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> }</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class=""> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</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="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = value</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><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:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> barSetA:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Set</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="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">8</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="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">9</span><span style="font-variant-ligatures:no-common-ligatures" class="">)]</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:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> barSetB:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Set</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="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">9</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="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">10</span><span style="font-variant-ligatures:no-common-ligatures" class="">)]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> barResultC = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">barSetA</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">intersection</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="">barSetB</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="font-variant-ligatures:no-common-ligatures" class="">// {{NSObject, value 9}}</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)" class="">























</p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> barResultD = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">barSetA</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">subtracting</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="">barSetB</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="font-variant-ligatures:no-common-ligatures" class="">// {{NSObject, value 8}}</span></div><div class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div></div><div class="gmail_default"><font face="georgia, serif" class="">Gladly I find it <a href="http://stackoverflow.com/questions/32726524/swift-2-0-set-not-working-as-expected-when-containing-nsobject-subclass" class="">here</a>.&nbsp;</font></div><div class="gmail_default"><font face="georgia, serif" class=""><br class=""></font></div><div class="gmail_default"><font face="georgia, serif" class="">Zhaoxin</font></div><div class="gmail_default"><br class=""></div><div class="gmail_default"><font face="georgia, serif" class=""><br class=""></font></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Mar 29, 2017 at 3:50 AM, Zhao Xin <span dir="ltr" class="">&lt;<a href="mailto:owenzx@gmail.com" target="_blank" class="">owenzx@gmail.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="gmail_default" style="font-family:georgia,serif">Please see the code first.</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">import</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Foundation</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">class</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Foo:</span><span style="font-variant-ligatures:no-common-ligatures" class="">Hashable</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> hashValue: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class=""> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">return</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="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">static</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> ==(lhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">, rhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Bool</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> lhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> == rhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class=""> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</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="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = value</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><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:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> fooSetA:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Set</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="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">8</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="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">9</span><span style="font-variant-ligatures:no-common-ligatures" class="">)]</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:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> fooSetB:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Set</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="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">9</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="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">10</span><span style="font-variant-ligatures:no-common-ligatures" class="">)]</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:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> fooResultC = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">fooSetA</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">intersection</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="">fooSetB</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="">// {{value 9}}</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:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> fooResultD = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">fooSetA</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">subtracting</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="">fooSetB</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="">// {{value 8}}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">class</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Bar:</span><span style="font-variant-ligatures:no-common-ligatures" class="">NSObject</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">override</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> hashValue: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class=""> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">return</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="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">static</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> ==(lhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">, rhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Bool</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> lhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> == rhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class=""> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</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="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = value</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><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:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> barSetA:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Set</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="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">8</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="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">9</span><span style="font-variant-ligatures:no-common-ligatures" class="">)]</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:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> barSetB:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Set</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="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">9</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="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">10</span><span style="font-variant-ligatures:no-common-ligatures" class="">)]</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:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> barResultC = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">barSetA</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">intersection</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="">barSetB</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="">// Set([])</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> barResultD = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">barSetA</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">subtracting</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="">barSetB</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="font-variant-ligatures:no-common-ligatures" class="">// {{NSObject, value 9}, {NSObject, value 8}}</span></div></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">Behaviors of `func intersection(Set&lt;Set.Element&gt;)<wbr class="">` and `func subtracting(Set&lt;Set.Element&gt;)` were different between normal Swift class and NSObject subclasses. I had thought they should be the same. It seemed that Set&lt;NSObject&gt; relied on addresses of NSObject instances instead of their hashValues. That made the Set useless.</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">Swift version: 3.1 (swiftlang-802.0.48 clang-802.0.48)</div><div class="gmail_default" style="font-family:georgia,serif">Xcode&nbsp;8.3 (8E162)</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div></div>
</blockquote></div><br class=""></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=""></div></body></html>