How would you check equality between a compile-time protocol reference and a conformance? #35
Answered
by
Azoy
NSExceptional
asked this question in
Q&A
|
i.e. you want to check if |
Answered by
Azoy
Apr 21, 2021
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 |
2 replies
Answer selected by
NSExceptional
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
ExistentialMetadatais not ABI stable so it can change in the future, but for ex…