How would you check equality between a compile-time protocol reference and a conformance? #35
-
i.e. you want to check if |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
So doing something like let equatableMetadata = reflect(_typeByName("SQ")!) as! ExistentialMetadata
let equatable = equatableMetadata.protocols[0]
for conformance in metadata.conformances {
if conformance.protocol == equatable { /* ... */ }
} I'm thinking I may want to make the conformances a dictionary with the protocol as the key instead. Keep in mind that |
Beta Was this translation helpful? Give feedback.
So doing something like
reflect(Equatable.self)
isn't possible yet (soon it will be because of https://forums.swift.org/t/se-0309-unlock-existential-types-for-all-protocols/47515 !), but if one really wants to do this kind of operation now you could do something pretty hacky.I'm thinking I may want to make the conformances a dictionary with the protocol as the key instead. Keep in mind that
ExistentialMetadata
is not ABI stable so it can change in the future, but for ex…