• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Iterating over a classes methods?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Iterating over a classes methods?


  • Subject: Re: Iterating over a classes methods?
  • From: "John C. Randolph" <email@hidden>
  • Date: Fri, 27 Dec 2002 14:35:49 -0800

On Monday, December 23, 2002, at 11:47 PM, Victor Ng wrote:

Is there a way to iterate over the list of messages that an object will respond to?

I did it like this: (slightly modified from an example that Erik Buck posted here some time ago.)

NSArray *
methodNamesForClass(Class aClass)
{
Class
class = aClass;

NSMutableArray
*methodNames = [NSMutableArray array];
// *methodNames = (class->super_class ? methodNamesForClass(class->super_class) : [NSMutableArray array]);

struct objc_method_list
*methods;

void
*iterator = NULL;

while(methods = class_nextMethodList(aClass, &iterator ))
{
int i = methods->method_count;

while(i--)
{
Method currentMethod = &methods->method_list[i];
[methodNames addObject: NSStringFromSelector(currentMethod->method_name)];
}
}
return [NSArray arrayWithArray:methodNames];
}

The method above will show you only the methods implemented in aClass, not its inherited methods. To get all of the method names, comment out the line "*methodNames = [NSMutableArray array];", and uncomment the line after it.

-jcr

John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Iterating over a classes methods? (From: Victor Ng <email@hidden>)

  • Prev by Date: *Simple* Musical note generation APIs?
  • Next by Date: Re: Mac OS X's Dock color
  • Previous by thread: Re: Iterating over a classes methods?
  • Next by thread: storing passwords
  • Index(es):
    • Date
    • Thread