Every Swift Value Type Should Be Equatable
To be truly equal, the
==
operator not only needs to be implemented, but it needs to be implemented in such a way that it behaves as we’d expect when doing our comparisons. During the talk, Doug mentioned three important properties of equality that need to hold for our Value Types:
- The comparison must be reflexive
- The comparison must be symmetric
- The comparison must be transitive
[…]
If Reference Types are involved with your Value Type implementation, things could get a little more complicated. “Complicated” probably isn’t the right word… but you do have to think a little more about your Type’s equality semantics.