user13489394
user13489394

Reputation:

Type to unrelated type Protocol

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

Answers (1)

PGDev
PGDev

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

Related Questions