Mastering Equatable, Comparable, and Hashable in Swift

When building applications in Swift, you constantly need to compare objects, sort arrays, or store unique items in a Set or Dictionary. To do this efficiently, Swift relies on three fundamental protocols: Equatable, Comparable, and Hashable. While these protocols are easy to adopt, their behavior differs significantly depending on whether you are using a struct or a class. Let’s break down why we need them and how to implement them correctly. ...

June 29, 2026 · 5 min