If you take a look on the equal operator for tuples, you will see that both
elements of the tuple must conform to Equatable.
public func ==<A, B>(lhs: (A, B), rhs: (A, B)) -> Bool where A : Equatable, B :
Equatable
Your SomeClass doesn’t conforme to Equatable so it doesn’t work. If you just
add the conformance it’ll work.
class SomeClass { }
extension SomeClass: Equatable {
static func ==(_ lhs: SomeClass, _ rhs: SomeClass) -> Bool {
return lhs === rhs
}
}
let c1 = SomeClass()
let t1 = ("abc", c1)
let t2 = ("abc", c1)
t1 == t2 // legal
// true
Regards,
Henrique Valcanaia
Co-founder | iOS Engineer @ Darkshine.io <http://darkshine.io/>
Computer Engineering undergraduate student @ Inf UFRGS
http://bit.ly/valcanaia <http://bit.ly/valcanaia>
> On 9 Jul 2017, at 12:11, David Baraff via swift-users <[email protected]>
> wrote:
>
> Given 2-tuples of type (T1, T2), you should be able to invoke the == operator
> if you could on both types T1 and T2, right? i.e.
>
> (“abc”, 3) == (“abc”, 4) // legal
>
> but:
>
> class SomeClass {
> static public func ==(_ lhs:SomeClass, _ rhs:SomeClass) -> Bool {
> return lhs === rhs
> }
> }
>
> let c1 = SomeClass()
> let c2 = SomeClass()
>
> let t1 = ("abc", c1)
> let t2 = ("abc", c2)
>
> c1 == c2 // legal
> t1 == t2 // illegal
>
>
>
>
> Why is t1 == t2 not legal given that c1 == c2 IS legal?
>
>
> _______________________________________________
> swift-users mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-users
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users