FROM : John C. Randolph
DATE : Fri Dec 27 23:35:49 2002
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_removed>> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
DATE : Fri Dec 27 23:35:49 2002
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_removed>> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
| Related mails | Author | Date |
|---|---|---|
| Victor Ng | Dec 24, 08:47 | |
| Timothy Ritchey | Dec 24, 15:33 | |
| gparker-apple | Dec 24, 20:10 | |
| John C. Randolph | Dec 27, 23:35 |






Cocoa mail archive

