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 https://github.com/wickwirew/Runtime.
No suitable runtime methods in https://github.com/apple/swift/blob/main/stdlib/public/runtime/ProtocolConformance.cpp.

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

1 Like
Terms of Service

Privacy Policy

Cookie Policy