<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta content="text/html; charset=utf-8">
</head>
<body class="" style="word-wrap:break-word">
<div id="compose-container" itemscope="" itemtype="https://schema.org/EmailMessage" style="direction:ltr">
<span itemprop="creator" itemscope="" itemtype="https://schema.org/Organization"><span itemprop="name"></span></span>
<div>
<div style="direction:ltr">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><br>
</div>
<div style="direction:ltr">Zhaoxin</div>
<div><br>
</div>
<div class="acompli_signature">Get <a href="https://aka.ms/o0ukef">Outlook for iOS</a></div>
</div>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Saagar Jha <saagar@saagarjha.com><br>
<b>Sent:</b> Wednesday, March 29, 2017 11:47:51 AM<br>
<b>To:</b> Zhao Xin<br>
<b>Cc:</b> Swift Users List<br>
<b>Subject:</b> Re: [swift-users] Set with element of NSObject subclasses didn't work as expected</font>
<div> </div>
</div>
<div>NSObject’s hash (which Set uses) is done via 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="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; word-wrap:break-word">
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 <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> 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?) -> 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. </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=""> </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>
<p class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""> </span><br class="webkit-block-placeholder">
</p>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style=""> </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=""> </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="">) ->
</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=""> </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=""> }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(0,132,0)">
<span class="" style=""> </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=""> </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="">?) ->
</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=""> </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=""> </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=""> }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(186,45,162)">
<span class="" style=""> </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=""> }</span></div>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; color:rgb(186,45,162)">
<span class="" style=""> </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>
<p class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""> </span><br class="webkit-block-placeholder">
</p>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style=""> </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=""> </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=""> }</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>. </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="">
<<a href="mailto:owenzx@gmail.com" target="_blank" class="">owenzx@gmail.com</a>></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=""> </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>
<p class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""> </span><br class="webkit-block-placeholder">
</p>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<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=""> </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="">) ->
</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=""> </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=""> }</span></div>
<p class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""> </span><br class="webkit-block-placeholder">
</p>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style=""> </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=""> </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=""> }</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=""> </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>
<p class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""> </span><br class="webkit-block-placeholder">
</p>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style=""> </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=""> </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="">) ->
</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=""> </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=""> }</span></div>
<p class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo; min-height:13px">
<span class="" style=""> </span><br class="webkit-block-placeholder">
</p>
<div class="" style="margin:0px; font-size:11px; line-height:normal; font-family:menlo">
<span class="" style=""> </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=""> </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=""> }</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<Set.Element>)<wbr class="">` and `func subtracting(Set<Set.Element>)` were different between normal Swift class and NSObject subclasses. I had thought they should
be the same. It seemed that Set<NSObject> 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 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>
</div>
</body>
</html>