views:

315

answers:

3

In Objective-C i can test wether a given class or instance responds to certain selectors. But how can query a class or instance for all its methods or properties of a class (e.g. a list of all methods or properties)?

Wether documented or not, it has to be possible as e.g. WebView can query a plugins scriptable object for all methods and properties if they should be visible to scripts or not.

+1  A: 

This is possible via objc_method_list. In order to enumerate your methods, you will have to register all your methods before hand.

The process is straight forward: after you've declared your function you can create an instance of objc_method and register the function name. Then add the objc_method to a objc_method_list and finally pass the objc_method_list to class_addMethods..

Here is a link to get you started: http://theocacao.com/document.page/327

+1  A: 

I wrote a little app that does this:

http://x-cake.ning.com/profiles/blogs/browsing-the-objc-runtime-on?xg_source=activity

NSResponder
+4  A: 

You'll want to use the Objective C runtime methods, see here: http://developer.apple.com/mac/library/documentation/cocoa/Reference/ObjCRuntimeRef/Reference/reference.html

Ben Gottlieb