Re: Runtime class info in ObjC/Cocoa
Re: Runtime class info in ObjC/Cocoa
- Subject: Re: Runtime class info in ObjC/Cocoa
- From: Greg Titus <email@hidden>
- Date: Fri, 27 Jul 2001 10:08:11 -0700
On Friday, July 27, 2001, at 09:03 AM, Luc Heinrich wrote:
Hi,
Is there a way, in Objective-C in general and/or in Cocoa specifically,
to discover at runtime the methods that a particular class/instance
implements ?
In Java, you just have to do that:
Method[] methodList = someClass.getMethods();
Is there anything similar in ObjC/Cocoa ? Something that could give me
back a SEL list, which I could then put into the magic
'NSStringFromSelector' thingy, for example... I had a look at the
NSObject class, and various objc runtime headers, but I did not found
something that could help.
Any clue ? Thanks.
Look at /usr/include/objc/objc-class.h and then do something like this:
- (void)logMethodsForClass:(Class)aClass
{
void *iterator = 0;
struct objc_method_list *methodList;
int index;
SEL selector;
while (methodList = class_nextMethodList(aClass, &iterator) {
for (index = 0; index < methodList->method_count; index++) {
selector = methodList->method_list[index].method_name;
NSLog(@"Next selector: %@", NSStringFromSelector(selector));
}
}
}
Hope this helps,
-Greg