• 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: Runtime class info in ObjC/Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Runtime class info in ObjC/Cocoa
      • From: Luc Heinrich <email@hidden>
References: 
 >Runtime class info in ObjC/Cocoa (From: Luc Heinrich <email@hidden>)

  • Prev by Date: Re: Easy Question / Complicated buttons
  • Next by Date: Re: Running normally-GUI Cocoa apps as background processes
  • Previous by thread: Runtime class info in ObjC/Cocoa
  • Next by thread: Re: Runtime class info in ObjC/Cocoa
  • Index(es):
    • Date
    • Thread