Skip to content

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
Discussion options

You must be logged in to vote

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.

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 ExistentialMetadata is not ABI stable so it can change in the future, but for ex…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@NSExceptional
Comment options

@NSExceptional
Comment options

Answer selected by NSExceptional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants