I am trying to compare an array of types with an another array of types
Questions
Why doesn't following code doesn't compile? Comparing the type t1 == t2 compiles ok but [t1] == [t2] doesn't compile.
How can I compare an array of types with another array of types?
Is iterating over them the only option?
Code
class Car {}
class Bike {}
let c = Car()
let b = Bike()
let t1 = type(of: c)
let t2 = type(of: b)
print(t1 == t2) // compiles ok
print([t1] == [t2]) // Type 'Car.Type' cannot conform to 'Equatable'
Conformance of Array to Equatable requires its Element to also conform to Equatable. At the time of this writing, metatypes cannot conform to protocols and their == operator is implemented as a special case by essentially wrapping the metatype into ObjectIdentifier. You can achieve a similar result by creating a wrapper type around your metatype and conform it to Equatable (and even Hashable) by using ObjectIdentifier.