MAObjCRuntime icon indicating copy to clipboard operation
MAObjCRuntime copied to clipboard

Query Class Methods

Open rjregenold opened this issue 13 years ago • 5 comments

Not sure if you're interested in this pull request or not, but I needed to pull back an array of class methods on an object and added a method to do so. It served my purposes, so I figured it may be useful for others.

Thanks!

rjregenold avatar Nov 03 '11 15:11 rjregenold

What's the advantage over simply doing [[class rt_class] rt_methods]? I guess it's a bit confusing. Seems to me that the best approach might be to rename rt_methods as rt_instanceMethods, then make a new rt_methods that fetches the methods that the receiver itself responds to.

mikeash avatar Nov 03 '11 23:11 mikeash

Ah, I didn't think about doing [[class rt_class] rt_methods]. I do like the idea of changing rt_methods to rt_instanceMethods and having rt_methods query the methods of the receiver. Are you concerned about breaking backwards compatibility?

rjregenold avatar Nov 04 '11 15:11 rjregenold

I'm not concerned about breaking backwards compatibility, but I wouldn't want to do so silently, so having a new rt_methods that does something different from before wouldn't be ideal. Hmm.....

mikeash avatar Nov 04 '11 19:11 mikeash

class_copyMethodList seems to only return instance methods no matter what is passed to it??

franklinwise avatar Aug 28 '13 21:08 franklinwise

actually... found this to work for getting Class Methods

const char *className = class_getName(self.class);
Class myClass = (Class)objc_getMetaClass(className);
Method *methods = class_copyMethodList(myClass, &methodCount);

franklinwise avatar Aug 28 '13 21:08 franklinwise