How to properly implement the Equatable protocol in a class hierarchy? : <p>I'm trying to implement the <code>==</code> operator (from <code>Equatable</code>) in a base class and its subclasses in Swift 3. All of the classes will only be used in Swift so I do not want to involve <code>NSObject</code> or the <code>NSCopying</code> protocol.</p>

<p>I started with a base class and a subclass:</p>

<pre><code>class Base {
    var x : Int
}

class Subclass : Base {
    var y : String
}
</code></pre>

<p>Now I wanted to add <code>Equatable</code> and the <code>==</code> operator to <code>Base</code>. Seems simple enough. Copy the <code>==</code> operator signature from the documentation:</p>

<pre><code>class Base : Equatable {
    var x : Int

    static func == (lhs: Base, rhs: Base) -&gt; Bool {
        return lhs.x == rhs.x
    }
}
</code></pre>

<p>So far so good. Now for the subclass:</p>

<pre><code>class Subclass : Base {
    static override func == (lhs: Base, rhs: Base) -&gt; Bool {
        return true
    }
}
</code></pre>

<p>But this results in an error:</p>

<blockquote>
  <p>Operator function overrides a 'final' operator function</p>
</blockquote>

<p>OK. After some research (still learning Swift 3) I learn that <code>static</code> can be replaced with <code>class</code> to indicate the type method can be overridden.</p>

<p>So I attempt to change <code>static</code> to <code>class</code> in <code>Base</code>:</p>

<pre><code>class Base : Equatable {
    var x : Int

    class func == (lhs: Base, rhs: Base) -&gt; Bool {
        return lhs.x == rhs.x
    }
}
</code></pre>

<p>But that results in a new error:</p>

<blockquote>
  <p>Operator '==' declared in non-final class 'Base' must be 'final'</p>
</blockquote>

<p>Ugh. This is far more complicated than it should be.</p>

<p>How do I implement the <code>Equatable</code> protocol and the <code>==</code> operator properly in a base class and a subclass?</p>
