livingtech livingtech -5 years ago 164
iOS Question

How do I determine what protocols a class conforms to in swift?

In objective-c, you can always check a class's protocols through its public headers. But if you have a class in swift, how do you know what protocols it conforms to? Is this even possible?

(Yes, I realize Apple's documentation lists the protocols it conforms to, but that doesn't seem like a real solution, since you might be working with a private framework or have some other theoretical reason for wanting to know an object's protocols.)

Also, yes, I know you can check for a specific protocol using the technique outlined here:

Answer Source

I don't believe you can do it without leaning on the Objective-C runtime. Import ObjectiveC and use the class_copyProtocolList() function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download