Search code examples
objective-cxcodexcode4

How do I get list of all classes conform to certain protocol in Xcode 4?


I am new to Xcode. I want to know how can I know all classes conform to certain protocol in Xcode 4.3.1? And how can I know all subclasses of one class?


Solution

  • Use the Objective-C runtime functions.

    • objc_getClassList to get the list of Classes
    • class_getSuperclass or the -superclass method to walk the superclass chain
    • class_conformsToProtocol or the -conformsToProtocol: method to check if a class conforms to a protocol