<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="">Yes, this is a serious shortcoming in the transition to Swift as the main application programming language for Apple platforms.<div class=""><br class=""></div><div class="">With the existing architecture (lack of stable Swift ABI) system frameworks and any binary distributed frameworks still have to be written in Objective-C. If you are already an experienced developer of Apple platforms, you already know the behavior and expectations of ObjC runtime and NSObject family. But new developers are coming to the platform everyday and now they are starting with Swift. This really needs to be better addressed as more people start developing for Apple platforms using Swift with no prior knowledge of ObjC runtime and NSObject.</div><div class=""><br class=""></div><div class="">I think the best way to draw some attention to this is by filing bug reports on lack of adequate documentation, at least.</div><div class=""><br class=""></div><div class="">Also, please note that if you want to define operators that act on class hierarchies, you should put all of the logic of the operator in a method and have the operator simply delegate to the method to preserve (some) polymorphism. Although infix operators can’t easily be fully polymorphic, given the lack of multiple (or at least dual) dispatch. The problematic part of getting Equatable right in this case is that any instance of a subclass by definition should work as an instance of its superclass and this can create bugs if you are not careful. `Equatable` protocol requires both sides of the equality test to have identical type for the mathematical definition of equality to hold. In practice, you may need to relax this in some situations, but you should be fully aware of what you are doing.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 29, 2017, at 2:36 AM, 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="">

<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252" class="">
<meta content="text/html; charset=utf-8" class="">

<div class="" style="word-wrap:break-word">
<div id="compose-container" itemscope="" itemtype="https://schema.org/EmailMessage" style="direction:ltr" class="">
<span itemprop="creator" itemscope="" itemtype="https://schema.org/Organization" class=""><span itemprop="name" class=""></span></span>
<div class="">
<div style="direction:ltr" class="">Now I understand it. What I don't understand is why there is nowhere metioning this. All docs are talking about Hashable, clearly that NSObject didn't rely on it.</div>
<div class=""><br class="">
</div>
<div style="direction:ltr" class="">Zhaoxin</div>
<div class=""><br class="">
</div>
<div class="acompli_signature">Get <a href="https://aka.ms/o0ukef" class="">Outlook for iOS</a></div>
</div>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%" class="">
<div id="divRplyFwdMsg" dir="ltr" class=""><font face="Calibri, sans-serif" style="font-size:11pt" class=""><b class="">From:</b> Saagar Jha &lt;<a href="mailto:saagar@saagarjha.com" class="">saagar@saagarjha.com</a>&gt;<br class="">
<b class="">Sent:</b> Wednesday, March 29, 2017 11:47:51 AM<br class="">
<b class="">To:</b> Zhao Xin<br class="">
<b class="">Cc:</b> Swift Users List<br class="">
<b class="">Subject:</b> Re: [swift-users] Set with element of NSObject subclasses didn't work as expected</font>
<div class="">&nbsp;</div>
</div>
<div 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 class="" style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;">
Saagar Jha</div>
</div>
<br class="">
<div class="">
<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 class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(112,61,170)">
<span class="" style="color:rgb(186,45,162)">class</span><span class="" style=""> Bar:</span><span class="" style="">NSObject</span><span class="" style=""> {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> value:</span><span class="" style="color:rgb(112,61,170)">Int</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class="">
<span class="" style="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">override</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">public</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">var</span><span class="" style=""> hashValue:
</span><span class="" style="color:rgb(112,61,170)">Int</span><span class="" style=""> {
</span><span class="" style="color:rgb(186,45,162)">return</span><span class="" style="">
</span><span class="" style="color:rgb(79,129,135)">value</span><span class="" style=""> }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">public</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">static</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">func</span><span class="" style=""> ==(lhs:
</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">, rhs:
</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">) -&gt;
</span><span class="" style="color:rgb(112,61,170)">Bool</span><span class="" style=""> {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">return</span><span class="" style=""> lhs.</span><span class="" style="color:rgb(79,129,135)">value</span><span class="" style=""> == rhs.</span><span class="" style="color:rgb(79,129,135)">value</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(0,132,0)">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="">// required by NSObjectProtocol</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">override</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">func</span><span class="" style=""> isEqual(</span><span class="" style="color:rgb(186,45,162)">_</span><span class="" style=""> object:
</span><span class="" style="color:rgb(186,45,162)">Any</span><span class="" style="">?) -&gt;
</span><span class="" style="color:rgb(112,61,170)">Bool</span><span class="" style=""> {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">if</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> rhs = object
</span><span class="" style="color:rgb(186,45,162)">as</span><span class="" style="">?
</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style=""> {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">return</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">self</span><span class="" style="">
</span><span class="" style="color:rgb(49,89,93)">==</span><span class="" style=""> rhs</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(186,45,162)">
<span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="">return</span><span class="" style="">
</span><span class="" style="">false</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(186,45,162)">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="">override</span><span class="" style="">
</span><span class="" style="">var</span><span class="" style=""> hash: </span><span class="" style="color:rgb(112,61,170)">Int</span><span class="" style=""> {
</span><span class="" style="">return</span><span class="" style=""> </span><span class="" style="">self</span><span class="" style="">.</span><span class="" style="color:rgb(79,129,135)">hashValue</span><span class="" style=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class="">
<span class="" style="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">init</span><span class="" style="">(</span><span class="" style="color:rgb(186,45,162)">_</span><span class="" style=""> value:</span><span class="" style="color:rgb(112,61,170)">Int</span><span class="" style="">)
 {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">self</span><span class="" style="">.</span><span class="" style="color:rgb(79,129,135)">value</span><span class="" style=""> = value</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">}</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""></span><br class="">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> barSetA:</span><span class="" style="color:rgb(112,61,170)">Set</span><span class="" style=""> = [</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">8</span><span class="" style="">),
</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">9</span><span class="" style="">)]</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> barSetB:</span><span class="" style="color:rgb(112,61,170)">Set</span><span class="" style=""> = [</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">9</span><span class="" style="">),
</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">10</span><span class="" style="">)]</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(0,132,0)">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> barResultC =
</span><span class="" style="color:rgb(79,129,135)">barSetA</span><span class="" style="">.</span><span class="" style="color:rgb(62,30,129)">intersection</span><span class="" style="">(</span><span class="" style="color:rgb(79,129,135)">barSetB</span><span class="" style="">)
</span><span class="" style="">// {{NSObject, value 9}}</span></div><p class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(112,61,170)">
</p>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(0,132,0)">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> barResultD =
</span><span class="" style="color:rgb(79,129,135)">barSetA</span><span class="" style="">.</span><span class="" style="color:rgb(62,30,129)">subtracting</span><span class="" style="">(</span><span class="" style="color:rgb(79,129,135)">barSetB</span><span class="" style="">)
</span><span class="" style="">// {{NSObject, value 8}}</span></div>
<div class=""><span class="" style=""><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 class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="color:rgb(186,45,162)">import</span><span class="" style=""> Foundation</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""></span><br class="">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(112,61,170)">
<span class="" style="color:rgb(186,45,162)">class</span><span class="" style=""> Foo:</span><span class="" style="">Hashable</span><span class="" style=""> {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> value:</span><span class="" style="color:rgb(112,61,170)">Int</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class="">
<span class="" style="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">public</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">var</span><span class="" style=""> hashValue:
</span><span class="" style="color:rgb(112,61,170)">Int</span><span class="" style=""> {
</span><span class="" style="color:rgb(186,45,162)">return</span><span class="" style="">
</span><span class="" style="color:rgb(79,129,135)">value</span><span class="" style=""> }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">public</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">static</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">func</span><span class="" style=""> ==(lhs:
</span><span class="" style="color:rgb(79,129,135)">Foo</span><span class="" style="">, rhs:
</span><span class="" style="color:rgb(79,129,135)">Foo</span><span class="" style="">) -&gt;
</span><span class="" style="color:rgb(112,61,170)">Bool</span><span class="" style=""> {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">return</span><span class="" style=""> lhs.</span><span class="" style="color:rgb(79,129,135)">value</span><span class="" style=""> == rhs.</span><span class="" style="color:rgb(79,129,135)">value</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class="">
<span class="" style="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">init</span><span class="" style="">(</span><span class="" style="color:rgb(186,45,162)">_</span><span class="" style=""> value:</span><span class="" style="color:rgb(112,61,170)">Int</span><span class="" style="">)
 {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">self</span><span class="" style="">.</span><span class="" style="color:rgb(79,129,135)">value</span><span class="" style=""> = value</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">}</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""></span><br class="">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> fooSetA:</span><span class="" style="color:rgb(112,61,170)">Set</span><span class="" style=""> = [</span><span class="" style="color:rgb(79,129,135)">Foo</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">8</span><span class="" style="">),
</span><span class="" style="color:rgb(79,129,135)">Foo</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">9</span><span class="" style="">)]</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> fooSetB:</span><span class="" style="color:rgb(112,61,170)">Set</span><span class="" style=""> = [</span><span class="" style="color:rgb(79,129,135)">Foo</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">9</span><span class="" style="">),
</span><span class="" style="color:rgb(79,129,135)">Foo</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">10</span><span class="" style="">)]</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> fooResultC =
</span><span class="" style="color:rgb(79,129,135)">fooSetA</span><span class="" style="">.</span><span class="" style="color:rgb(62,30,129)">intersection</span><span class="" style="">(</span><span class="" style="color:rgb(79,129,135)">fooSetB</span><span class="" style="">)
</span><span class="" style="color:rgb(0,132,0)">// {{value 9}}</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> fooResultD =
</span><span class="" style="color:rgb(79,129,135)">fooSetA</span><span class="" style="">.</span><span class="" style="color:rgb(62,30,129)">subtracting</span><span class="" style="">(</span><span class="" style="color:rgb(79,129,135)">fooSetB</span><span class="" style="">)
</span><span class="" style="color:rgb(0,132,0)">// {{value 8}}</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""></span><br class="">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""></span><br class="">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(112,61,170)">
<span class="" style="color:rgb(186,45,162)">class</span><span class="" style=""> Bar:</span><span class="" style="">NSObject</span><span class="" style=""> {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> value:</span><span class="" style="color:rgb(112,61,170)">Int</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class="">
<span class="" style="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">override</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">public</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">var</span><span class="" style=""> hashValue:
</span><span class="" style="color:rgb(112,61,170)">Int</span><span class="" style=""> {
</span><span class="" style="color:rgb(186,45,162)">return</span><span class="" style="">
</span><span class="" style="color:rgb(79,129,135)">value</span><span class="" style=""> }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">public</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">static</span><span class="" style="">
</span><span class="" style="color:rgb(186,45,162)">func</span><span class="" style=""> ==(lhs:
</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">, rhs:
</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">) -&gt;
</span><span class="" style="color:rgb(112,61,170)">Bool</span><span class="" style=""> {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">return</span><span class="" style=""> lhs.</span><span class="" style="color:rgb(79,129,135)">value</span><span class="" style=""> == rhs.</span><span class="" style="color:rgb(79,129,135)">value</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class="">
<span class="" style="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">init</span><span class="" style="">(</span><span class="" style="color:rgb(186,45,162)">_</span><span class="" style=""> value:</span><span class="" style="color:rgb(112,61,170)">Int</span><span class="" style="">)
 {</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="color:rgb(186,45,162)">self</span><span class="" style="">.</span><span class="" style="color:rgb(79,129,135)">value</span><span class="" style=""> = value</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">&nbsp; &nbsp; }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="">}</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""></span><br class="">
</div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> barSetA:</span><span class="" style="color:rgb(112,61,170)">Set</span><span class="" style=""> = [</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">8</span><span class="" style="">),
</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">9</span><span class="" style="">)]</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> barSetB:</span><span class="" style="color:rgb(112,61,170)">Set</span><span class="" style=""> = [</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">9</span><span class="" style="">),
</span><span class="" style="color:rgb(79,129,135)">Bar</span><span class="" style="">(</span><span class="" style="color:rgb(39,42,216)">10</span><span class="" style="">)]</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> barResultC =
</span><span class="" style="color:rgb(79,129,135)">barSetA</span><span class="" style="">.</span><span class="" style="color:rgb(62,30,129)">intersection</span><span class="" style="">(</span><span class="" style="color:rgb(79,129,135)">barSetB</span><span class="" style="">)
</span><span class="" style="color:rgb(0,132,0)">// Set([])</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(0,132,0)">
<span class="" style="color:rgb(186,45,162)">let</span><span class="" style=""> barResultD =
</span><span class="" style="color:rgb(79,129,135)">barSetA</span><span class="" style="">.</span><span class="" style="color:rgb(62,30,129)">subtracting</span><span class="" style="">(</span><span class="" style="color:rgb(79,129,135)">barSetB</span><span class="" style="">)
</span><span class="" style="">// {{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="">
<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>
</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>