Given that the underlying types are the same, I expected test2 to be true, not false:
protocol Foo {}
class Bar: NSObject, Foo {}
class Test {
func testCompare() {
let b = Bar()
let test1 = compare(expected: Bar.self, actual: b)
let c: Foo = b
let test2 = compare(expected: Bar.self, actual: c)
/*
(lldb) p expected
(@thick NSObject.Type) $R0 = SpokestackTests.Bar
(lldb) p type(of: actual).self
(SpokestackTests.Foo.Type) $R2 = SpokestackTests.Bar
*/
print(test1, test2) // true false
}
func compare<T>(expected: NSObject.Type, actual: T) -> Bool {
return expected == type(of: actual).self
}
}
Is this due to the difference between a concrete metatype of a class vs the existential metatype of a protocol instance?