<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">Hi Nick,</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Glad to help.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">but when using third party classes I don’t know if the hash values are comparable<br></blockquote><div><br></div><div class="gmail_default" style="font-family:georgia,serif">You can create an extension with a convenient init(:), which creates a new instance of  the super class basing on the instance of the sub class. That will guarantee the subtraction. Below code works in Xcode 7.3.1 with Swift 2.2.<br></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">import</span><span style="font-variant-ligatures:no-common-ligatures"> Foundation</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,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="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,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)">id</span><span style="font-variant-ligatures:no-common-ligatures"> == rhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">id</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(112,61,170)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,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="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> id:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Int</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,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></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,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)">id</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">required</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">init</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">_</span><span style="font-variant-ligatures:no-common-ligatures"> id:</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="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,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)">id</span><span style="font-variant-ligatures:no-common-ligatures"> = id</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">class</span><span style="font-variant-ligatures:no-common-ligatures"> Bar:</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></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">override</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,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></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,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)">id</span><span style="font-variant-ligatures:no-common-ligatures"> * </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">5</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">var</span><span style="font-variant-ligatures:no-common-ligatures"> fooSet:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Set</span><span style="font-variant-ligatures:no-common-ligatures">&lt;</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(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><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)">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)">7</span><span style="font-variant-ligatures:no-common-ligatures">)]</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">var</span><span style="font-variant-ligatures:no-common-ligatures"> barSet:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Set</span><span style="font-variant-ligatures:no-common-ligatures">&lt;</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(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)">7</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)">6</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)">5</span><span style="font-variant-ligatures:no-common-ligatures">)]</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">//fooSet.subtract(barSet) // error: cannot invoke &#39;subtract&#39; with an argument list of type &#39;(Set&lt;Bar&gt;)&#39;</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures">fooSet</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> = </span><span style="font-variant-ligatures:no-common-ligatures">fooSet</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(61,29,129)">subtract</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures">barSet</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(187,44,162)">as</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(112,61,170)">Set</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">&lt;</span><span style="font-variant-ligatures:no-common-ligatures">Foo</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">&gt;) </span><span style="color:rgb(0,132,0);font-family:menlo">// works, but not what we want</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">fooSet</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)">forEach</span><span style="font-variant-ligatures:no-common-ligatures"> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)">print</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">&quot;</span><span style="font-variant-ligatures:no-common-ligatures">\</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">(</span><span style="font-variant-ligatures:no-common-ligatures">$0.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">dynamicType</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">), id:</span><span style="font-variant-ligatures:no-common-ligatures">\</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">(</span><span style="font-variant-ligatures:no-common-ligatures">$0.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">id</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">)&quot;</span><span style="font-variant-ligatures:no-common-ligatures">) }</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">/*</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures"> Foo, id:7</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures"> Foo, id:10</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures"> Foo, id:9</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">*/</span></p><p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></p><p style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><font face="georgia, serif" color="#000000">Extension part.  You should comment above subtracting code before you run below code, as you want to make sure the result is not polluted.</font></span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(187,44,162)"><span style="font-variant-ligatures:no-common-ligatures">extension</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)">Foo</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> {</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">convenience</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">init</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">_</span><span style="font-variant-ligatures:no-common-ligatures"> instance:</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></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">self</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">init</span><span style="font-variant-ligatures:no-common-ligatures">(instance.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">id</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> anotherFooSet = { () -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Set</span><span style="font-variant-ligatures:no-common-ligatures">&lt;</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(187,44,162)">in</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">var</span><span style="font-variant-ligatures:no-common-ligatures"> set = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">Set</span><span style="font-variant-ligatures:no-common-ligatures">&lt;</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></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">for</span><span style="font-variant-ligatures:no-common-ligatures"> element </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">in</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">barSet</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">let</span><span style="font-variant-ligatures:no-common-ligatures"> foo = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">Foo</span><span style="font-variant-ligatures:no-common-ligatures">(element)</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        set.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)">insert</span><span style="font-variant-ligatures:no-common-ligatures">(foo)</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">return</span><span style="font-variant-ligatures:no-common-ligatures"> set</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}()</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures">fooSet</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> = </span><span style="font-variant-ligatures:no-common-ligatures">fooSet</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(61,29,129)">subtract</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures">anotherFooSet</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">fooSet</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)">forEach</span><span style="font-variant-ligatures:no-common-ligatures"> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)">print</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">&quot;</span><span style="font-variant-ligatures:no-common-ligatures">\</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">(</span><span style="font-variant-ligatures:no-common-ligatures">$0.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">dynamicType</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">), id:</span><span style="font-variant-ligatures:no-common-ligatures">\</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">(</span><span style="font-variant-ligatures:no-common-ligatures">$0.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">id</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">)&quot;</span><span style="font-variant-ligatures:no-common-ligatures">) }</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">/*</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures"> Foo, id:10</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures"> Foo, id:9</span></p>
<p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures">*/</span></p><p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></p><p style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"><font face="georgia, serif" color="#000000">Zhaoxin</font></span></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 1, 2016 at 9:41 PM, Nick Brook <span dir="ltr">&lt;<a href="mailto:nrbrook@gmail.com" target="_blank">nrbrook@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Zhao<div><br></div><div>Thanks for your response.</div><div><br></div><div>I understand your point, but when using third party classes I don’t know if the hash values are comparable, but for example I may want to have a set of ‘data&#39; (NSData) and a subset of ‘mutable data&#39; (NSMutableData), which point to the same objects. As a user of swift I would expect to be able to subtract Set&lt;NSMutableData&gt; from Set&lt;NSData&gt;.</div><div><br></div><div>Your last example perhaps works in Swift 3, so this may be fixed now, but in Swift 2 you get the error</div><div><br></div><div>Cannot invoke &#39;subtract&#39; with an argument list of type &#39;(Set&lt;Bar&gt;)’</div><div><br></div><div>Perhaps Swift 3 supports it with some additional safety around hashValue overriding or something.</div><div><br></div><div>Thanks<span class="HOEnZb"><font color="#888888"><br><div>
<br><span style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none">Nick</span><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div>
</div></font></span><div><div class="h5">
<br><div><blockquote type="cite"><div>On 1 Sep 2016, at 04:00, Zhao Xin &lt;<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</a>&gt; wrote:</div><br><div><div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I don&#39;t see the point. For example if an element in Set&lt;B&gt; and another element in Set&lt;A&gt; are with a same hash value. Neither of the elements should be subtracted. As they are in different types. And hash values between different types are not guaranteed to be comparable. </div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">import</span><span> Foundation</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">class</span><span> Foo:</span><span>Hashable</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    </span><span style="color:rgb(187,44,162)">var</span><span> value: </span><span style="color:rgb(112,61,170)">Int</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>    </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">var</span><span> hashValue: </span><span style="color:rgb(112,61,170)">Int</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>        </span><span style="color:rgb(187,44,162)">return</span><span> </span><span style="color:rgb(79,129,135)">value</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    }</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>    </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">static</span><span> </span><span style="color:rgb(187,44,162)">func</span><span> ==(lhs: </span><span style="color:rgb(79,129,135)">Foo</span><span>, rhs: </span><span style="color:rgb(79,129,135)">Foo</span><span>) -&gt; </span><span style="color:rgb(112,61,170)">Bool</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>        </span><span style="color:rgb(187,44,162)">return</span><span> lhs.</span><span style="color:rgb(79,129,135)">value</span><span> == rhs.</span><span style="color:rgb(79,129,135)">value</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    }</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>    </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    </span><span style="color:rgb(187,44,162)">required</span><span> </span><span style="color:rgb(187,44,162)">init</span><span>(</span><span style="color:rgb(187,44,162)">_</span><span> value:</span><span style="color:rgb(112,61,170)">Int</span><span>) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>        </span><span style="color:rgb(187,44,162)">self</span><span>.</span><span style="color:rgb(79,129,135)">value</span><span> = value</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">class</span><span> Bar:</span><span style="color:rgb(79,129,135)">Foo</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    </span><span style="color:rgb(187,44,162)">override</span><span> </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">var</span><span> hashValue: </span><span style="color:rgb(112,61,170)">Int</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>        </span><span style="color:rgb(187,44,162)">return</span><span> </span><span style="color:rgb(79,129,135)">value</span><span> * </span><span style="color:rgb(39,42,216)">10</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">let</span><span> foo = </span><span style="color:rgb(79,129,135)">Foo</span><span>(</span><span style="color:rgb(39,42,216)">10</span><span>)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">let</span><span> bar = </span><span style="color:rgb(79,129,135)">Bar</span><span>(</span><span style="color:rgb(39,42,216)">10</span><span>)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(79,129,135)"><span style="color:rgb(61,29,129)">print</span><span>(</span><span>foo</span><span>.</span><span>hashValue</span><span>) </span><span style="color:rgb(0,132,0)">// 10</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(79,129,135)"><span style="color:rgb(61,29,129)">print</span><span>(</span><span>bar</span><span>.</span><span>hashValue</span><span>) </span><span style="color:rgb(0,132,0)">// 100</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(61,29,129)">print</span><span>((</span><span style="color:rgb(79,129,135)">bar</span><span> </span><span style="color:rgb(187,44,162)">as</span><span> </span><span style="color:rgb(79,129,135)">Foo</span><span>).</span><span style="color:rgb(79,129,135)">hashValue</span><span>) </span><span>// 100 instead of 10</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="color:rgb(61,29,129)">print</span><span>(</span><span style="color:rgb(79,129,135)">foo</span><span> </span><span style="color:rgb(49,89,93)">==</span><span> </span><span style="color:rgb(79,129,135)">bar</span><span>) </span><span>// true</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(79,129,135)"><span style="color:rgb(61,29,129)">print</span><span>(</span><span>foo</span><span>.</span><span>hashValue</span><span> == </span><span>bar</span><span>.</span><span>hashValue</span><span>) </span><span style="color:rgb(0,132,0)">// false</span></div></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">As you can see in the above code, although `foo == bar` is true, `foo.hashValue == bar.hashValue` is not guaranteed to be true. As far as I know, Set&lt;T&gt; uses hash values instead of equations to compare the elements. So the results of a super class and its sub class are not guaranteed. Also, as `(bar as Foo).hashValue` is always the result of its own class, you can&#39;t get the results you want through casting.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">var</span><span> fooSet:</span><span style="color:rgb(112,61,170)">Set</span><span>&lt;</span><span style="color:rgb(79,129,135)">Foo</span><span>&gt; = [</span><span style="color:rgb(79,129,135)">Foo</span><span>(</span><span style="color:rgb(39,42,216)">10</span><span>), </span><span style="color:rgb(79,129,135)">Foo</span><span>(</span><span style="color:rgb(39,42,216)">9</span><span>), </span><span style="color:rgb(79,129,135)">Foo</span><span>(</span><span style="color:rgb(39,42,216)">8</span><span>), </span><span style="color:rgb(79,129,135)">Foo</span><span>(</span><span style="color:rgb(39,42,216)">7</span><span>)]</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">var</span><span> barSet:</span><span style="color:rgb(112,61,170)">Set</span><span>&lt;</span><span style="color:rgb(79,129,135)">Bar</span><span>&gt; = [</span><span style="color:rgb(79,129,135)">Bar</span><span>(</span><span style="color:rgb(39,42,216)">8</span><span>), </span><span style="color:rgb(79,129,135)">Bar</span><span>(</span><span style="color:rgb(39,42,216)">7</span><span>), </span><span style="color:rgb(79,129,135)">Bar</span><span>(</span><span style="color:rgb(39,42,216)">6</span><span>), </span><span style="color:rgb(79,129,135)">Bar</span><span>(</span><span style="color:rgb(39,42,216)">5</span><span>)]</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(79,129,135)"><span>fooSet</span><span>.</span><span style="color:rgb(61,29,129)">subtract</span><span>(</span><span>barSet</span><span>)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(79,129,135)">fooSet</span><span>.</span><span style="color:rgb(61,29,129)">forEach</span><span> { </span><span style="color:rgb(61,29,129)">print</span><span>(</span><span style="color:rgb(209,47,27)">&quot;</span><span>\</span><span style="color:rgb(209,47,27)">(</span><span>type(of:$0)</span><span style="color:rgb(209,47,27)">), value:</span><span>\</span><span style="color:rgb(209,47,27)">(</span><span>$0.</span><span style="color:rgb(79,129,135)">value</span><span style="color:rgb(209,47,27)">)&quot;</span><span>) }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>/*</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> Foo, value:10</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> Foo, value:9</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> Foo, value:8 // Here is a mystery, Foo(7) is </span>unreasonably missing.</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(79,129,135)">








</p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>*/</span></div></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">However, if you can guarantee the hash values are comparable, you still can get the results you want.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif"><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">class</span><span> Foo:</span><span>Hashable</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    </span><span style="color:rgb(187,44,162)">var</span><span> value: </span><span style="color:rgb(112,61,170)">Int</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>    </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">var</span><span> hashValue: </span><span style="color:rgb(112,61,170)">Int</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>        </span><span style="color:rgb(187,44,162)">return</span><span> </span><span style="color:rgb(79,129,135)">value</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    }</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>    </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">static</span><span> </span><span style="color:rgb(187,44,162)">func</span><span> ==(lhs: </span><span style="color:rgb(79,129,135)">Foo</span><span>, rhs: </span><span style="color:rgb(79,129,135)">Foo</span><span>) -&gt; </span><span style="color:rgb(112,61,170)">Bool</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>        </span><span style="color:rgb(187,44,162)">return</span><span> lhs.</span><span style="color:rgb(79,129,135)">value</span><span> == rhs.</span><span style="color:rgb(79,129,135)">value</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    }</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span>    </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    </span><span style="color:rgb(187,44,162)">required</span><span> </span><span style="color:rgb(187,44,162)">init</span><span>(</span><span style="color:rgb(187,44,162)">_</span><span> value:</span><span style="color:rgb(112,61,170)">Int</span><span>) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>        </span><span style="color:rgb(187,44,162)">self</span><span>.</span><span style="color:rgb(79,129,135)">value</span><span> = value</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">class</span><span> Bar:</span><span style="color:rgb(79,129,135)">Foo</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>    </span><span style="color:rgb(187,44,162)">var</span><span> name = </span><span style="color:rgb(209,47,27)">&quot;bar&quot;</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">var</span><span> fooSet:</span><span style="color:rgb(112,61,170)">Set</span><span>&lt;</span><span style="color:rgb(79,129,135)">Foo</span><span>&gt; = [</span><span style="color:rgb(79,129,135)">Foo</span><span>(</span><span style="color:rgb(39,42,216)">10</span><span>), </span><span style="color:rgb(79,129,135)">Foo</span><span>(</span><span style="color:rgb(39,42,216)">9</span><span>), </span><span style="color:rgb(79,129,135)">Foo</span><span>(</span><span style="color:rgb(39,42,216)">8</span><span>), </span><span style="color:rgb(79,129,135)">Foo</span><span>(</span><span style="color:rgb(39,42,216)">7</span><span>)]</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>
</span></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(187,44,162)">var</span><span> barSet:</span><span style="color:rgb(112,61,170)">Set</span><span>&lt;</span><span style="color:rgb(79,129,135)">Bar</span><span>&gt; = [</span><span style="color:rgb(79,129,135)">Bar</span><span>(</span><span style="color:rgb(39,42,216)">8</span><span>), </span><span style="color:rgb(79,129,135)">Bar</span><span>(</span><span style="color:rgb(39,42,216)">7</span><span>), </span><span style="color:rgb(79,129,135)">Bar</span><span>(</span><span style="color:rgb(39,42,216)">6</span><span>), </span><span style="color:rgb(79,129,135)">Bar</span><span>(</span><span style="color:rgb(39,42,216)">5</span><span>)]</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(79,129,135)"><span>fooSet</span><span>.</span><span style="color:rgb(61,29,129)">subtract</span><span>(</span><span>barSet</span><span>)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="color:rgb(79,129,135)">fooSet</span><span>.</span><span style="color:rgb(61,29,129)">forEach</span><span> { </span><span style="color:rgb(61,29,129)">print</span><span>(</span><span style="color:rgb(209,47,27)">&quot;</span><span>\</span><span style="color:rgb(209,47,27)">(</span><span>type(of:$0)</span><span style="color:rgb(209,47,27)">), value:</span><span>\</span><span style="color:rgb(209,47,27)">(</span><span>$0.</span><span style="color:rgb(79,129,135)">value</span><span style="color:rgb(209,47,27)">)&quot;</span><span>) }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>/*</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> Foo, value:10</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span> Foo, value:9</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span>




</span></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span>*/</span></div></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">Zhaoxin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 1, 2016 at 8:31 AM, Nick Brook via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I have a set, Set&lt;A&gt; and a subset of that, Set&lt;B&gt;, where B: A. I want to subtract Set&lt;B&gt; from Set&lt;A&gt;, but the subtract function signature specifies that the set elements must be the same type (S.Generator.Element == Element). I guess this is because Element is not required to be a class, simply hashable, therefore inheritance is not guaranteed? Is there any way this could be implemented in Set, in an extension, or what would be the most efficient way to perform that operation?<div><br></div><div>Thanks<span><font color="#888888"><br><div>
<br><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Nick</span></div></font></span></div></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>