MAObjCRuntime
MAObjCRuntime copied to clipboard
Query Class Methods
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!
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.
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?
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.....
class_copyMethodList seems to only return instance methods no matter what is passed to it??
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);