Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Class Methods #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

rjregenold
Copy link

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!

@mikeash
Copy link
Owner

mikeash commented Nov 3, 2011

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.

@rjregenold
Copy link
Author

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?

rt_methods will return an array of methods the receiver responds to.
added rt_instanceMethods which does what rt_methods used to do.
@mikeash
Copy link
Owner

mikeash commented Nov 4, 2011

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.....

@franklinwise
Copy link

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

@franklinwise
Copy link

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants