Re: Class method list
Re: Class method list
- Subject: Re: Class method list
- From: Sherm Pendley <email@hidden>
- Date: Thu, 19 Dec 2002 08:19:23 -0500
On Thursday, December 19, 2002, at 06:54 AM, TACKEL wrote:
Could you give me
any idea to get all the
methods available for
one class?
It depends on what you want to do with the list - There's more than one
way to do it.
The simplest way, of course, is to just look them up in the docs. But
I'm guessing that you knew that. :-)
The medium way is to use the "class-dump" tool, which you can install
easily using Fink. If getting the list of methods at compile-time is
what you need, "class-dump" is the way to go.
The hard way is to use the Objective-C runtime functions. If you need to
list the methods at runtime, this is what you'll want to do. Apple's
"The Objective-C Programming Language," available in PDF form at
apple.com, documents all of the runtime functions, but here's a
quick-n-dirty example:
#import <Foundation/Foundation.h>
#include <objc/objc-runtime.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Class ws = objc_getClass("NSObject");
void *iterator = 0;
struct objc_method_list *mlist;
int i;
mlist = class_nextMethodList(ws, &iterator);
while (mlist != NULL) {
for(i=0; i<mlist->method_count; i++) {
SEL aSel = mlist->method_list[i].method_name;
NSLog(@"Found selector %@", NSStringFromSelector(aSel));
}
mlist = class_nextMethodList(ws, &iterator);
}
[pool release];
return 0;
}
sherm--
UNIX: Where /sbin/init is Job 1.
_______________________________________________
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.