SLN SLN - 8 months ago 51
Swift Question

Tuples that contain a Boolean value can be compared. But the official documents says not

The Comparison Operators section of Basic Operators part of the Official documents claims that "Tuples that contain a Boolean value can't be compared"

You can't say a true value is larger or less than a false value. But you can write the equal comparison on Boolean values

print((1, true) == (2, true)) // --> false
print((1, true) == (1, true)) // --> true
print((1, true) != (2, true)) // --> true

Question Is it an error from the document or I misunderstood the content?


Comparison actually means testing for equality, greater than and less than.

Equality is possible, the other not.

The protocol Comparable inherits from Equatable. An object must implement the operators <, <=, >= and > to conform to the Comparable protocol, additional to == of Equatable.