Is there a way to know the list of protocols a struct/class conforms to

Hi,

I wanted to know if there is a way to know the list of protocols a struct/class conforms to.

struct myStruct: Numeric, Equitable {
 // some code to make myStruct Numeric and Equitable conformance.
}

// Some API as below which will list the protocol dependencies
ListProtocolDependencies(myStruct)
// Prints: Numeric, Equitable

I would like to know if there is any API or a library which gives us the details of protocols a struct/class conforms to.

BR

1 Like

No public API.
Nothing for that in GitHub - wickwirew/Runtime: A Swift Runtime library for viewing type info, and the dynamic getting and setting of properties..
No suitable runtime methods in swift/ProtocolConformance.cpp at main · apple/swift · GitHub.

And I think, I've seen somewhere an article explaining that it is intentionally unavailable, but I might be wrong.

1 Like