<aside>
🦊 元组的比较是根据每对相同类型的元素的比较进行的,当遇到第一对不相等的元素时,比较的结果将作为整个元祖比较的结果。
对元祖进行比较时,运算符必须能操作在每个类型上才行,如 <
不可操作在 Bool
类型上。
Swift 底层最多支持小于 7 个元素的元祖的比较,更多元素的比较需要自己实现。
</aside>
(1, "zebra") < (2, "apple") // true because 1 is less than 2; "zebra" and "apple" aren't compared
(3, "apple") < (3, "bird") // true because 3 is equal to 3, and "apple" is less than "bird"
(4, "dog") == (4, "dog") // true because 4 is equal to 4, and "dog" is equal to "dog”