Reputation:
I have a protocol and a class that extends that protocol
public protocol P {
}
public class C: P {
}
print(C.self is P.Protocol)
Please why do I get Cast from 'C.Type' to unrelated type 'P.Protocol' always fails
when printing?
Upvotes: 2
Views: 61
Reputation: 24341
The check for is
will work when you do it for an instance of type C
, i.e.
let c = C()
print(c is P) //true
Upvotes: 1