<div dir="ltr"><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></div><div class="gmail_default" style="font-family:georgia,serif"><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">import</span><span style="font-variant-ligatures:no-common-ligatures"> Foundation</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">class</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> Foo:</span><span style="font-variant-ligatures:no-common-ligatures">Hashable</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Int</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">var</span><span style="font-variant-ligatures:no-common-ligatures"> hashValue: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures:no-common-ligatures"> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">value</span><span style="font-variant-ligatures:no-common-ligatures"> }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">static</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> ==(lhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Foo</span><span style="font-variant-ligatures:no-common-ligatures">, rhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Foo</span><span style="font-variant-ligatures:no-common-ligatures">) -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Bool</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"> lhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">value</span><span style="font-variant-ligatures:no-common-ligatures"> == rhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">value</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">init</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">_</span><span style="font-variant-ligatures:no-common-ligatures"> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures:no-common-ligatures">) {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">value</span><span style="font-variant-ligatures:no-common-ligatures"> = value</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> fooSetA:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Set</span><span style="font-variant-ligatures:no-common-ligatures"> = [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Foo</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">8</span><span style="font-variant-ligatures:no-common-ligatures">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Foo</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">9</span><span style="font-variant-ligatures:no-common-ligatures">)]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> fooSetB:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Set</span><span style="font-variant-ligatures:no-common-ligatures"> = [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Foo</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">9</span><span style="font-variant-ligatures:no-common-ligatures">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Foo</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">10</span><span style="font-variant-ligatures:no-common-ligatures">)]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> fooResultC = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">fooSetA</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">intersection</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">fooSetB</span><span style="font-variant-ligatures:no-common-ligatures">) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)">// {{value 9}}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> fooResultD = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">fooSetA</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">subtracting</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">fooSetB</span><span style="font-variant-ligatures:no-common-ligatures">) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)">// {{value 8}}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">class</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> Bar:</span><span style="font-variant-ligatures:no-common-ligatures">NSObject</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Int</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">override</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">var</span><span style="font-variant-ligatures:no-common-ligatures"> hashValue: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures:no-common-ligatures"> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">value</span><span style="font-variant-ligatures:no-common-ligatures"> }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">public</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">static</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">func</span><span style="font-variant-ligatures:no-common-ligatures"> ==(lhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Bar</span><span style="font-variant-ligatures:no-common-ligatures">, rhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Bar</span><span style="font-variant-ligatures:no-common-ligatures">) -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Bool</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"> lhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">value</span><span style="font-variant-ligatures:no-common-ligatures"> == rhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">value</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">init</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">_</span><span style="font-variant-ligatures:no-common-ligatures"> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Int</span><span style="font-variant-ligatures:no-common-ligatures">) {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">value</span><span style="font-variant-ligatures:no-common-ligatures"> = value</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> barSetA:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Set</span><span style="font-variant-ligatures:no-common-ligatures"> = [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Bar</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">8</span><span style="font-variant-ligatures:no-common-ligatures">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Bar</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">9</span><span style="font-variant-ligatures:no-common-ligatures">)]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> barSetB:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Set</span><span style="font-variant-ligatures:no-common-ligatures"> = [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Bar</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">9</span><span style="font-variant-ligatures:no-common-ligatures">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Bar</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">10</span><span style="font-variant-ligatures:no-common-ligatures">)]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> barResultC = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">barSetA</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">intersection</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">barSetB</span><span style="font-variant-ligatures:no-common-ligatures">) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)">// Set([])</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> barResultD = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">barSetA</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">subtracting</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">barSetB</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">) </span><span style="font-variant-ligatures:no-common-ligatures">// {{NSObject, value 9}, {NSObject, value 8}}</span></p></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Behaviors of `func intersection(Set&lt;Set.Element&gt;)` 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></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></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div></div>