protocol Comparable| Inheritance |
Equatable
View Protocol Hierarchy →
|
|---|---|
| Import | import Swift |
Instance Methods
Returns true if lhs is equal to rhs.
Equality implies substitutability. When x == y, x and
y are interchangeable in any code that only depends on their
values.
Class instance identity as distinguished by triple-equals ===
is notably not part of an instance's value. Exposing other
non-value aspects of Equatable types is discouraged, and any
that are exposed should be explicitly pointed out in
documentation.
Equality is an equivalence relation
x == xistruex == yimpliesy == xx == yandy == zimpliesx == z
Inequality is the inverse of equality, i.e. !(x == y) iff
x != y.
Declaration
func ==(lhs: Self, rhs: Self) -> Bool
Declared In
Equatable
Instances of conforming types can be compared using relational operators, which define a strict total order.
A type conforming to
Comparableneed only supply the<and==operators; default implementations of<=,>,>=, and!=are supplied by the standard library:Axioms, in addition to those of
Equatable:x == yimpliesx <= y,x >= y,!(x < y), and!(x > y)x < yimpliesx <= yandy > xx > yimpliesx >= yandy < xx <= yimpliesy >= xx >= yimpliesy <= x