When I want to check if a type conforms to a simple protocol, I can use:
if let type = ValueType.self as? Codable.Type {}
When the protocol has associated type, for example RawRepresentable
has RawValue
, when I do:
if let type = ValueType.self as? RawRepresentable.Type {}
Compiler will show the following error:
Protocol 'RawRepresentable' can only be used as a generic constraint because it has Self or associated type requirements
So how to check conformance to protocol with associated type?
RawValue
in your case ofValueType
? :) – Cadell