Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa Tips #1

Cocoa Tips #1
Thread Tools
Junior Member
Join Date: Jan 2003
Status: Offline
Reply With Quote
Oct 17, 2003, 12:15 AM
 
Hello everyone. I've been lurking here for awhile now, and I want to contribute. So I'm starting a thing here, posting Cocoa tips about once per week. The first one I want to post is this:

Sometimes you will be 'reverse engineering' a framework or bundle, or will want to know more about certain AppKit or Foundation classes. Class-dump works in a great many situations, but when it doesn't, this code fragment will often do the trick:
Code:
void *iterator = 0; struct objc_method_list *mlist; int offset, i; i = offset = 0; mlist = class_nextMethodList( ourObjcClass, &iterator ); NSLog(@"the class %@ has the following methods:", ourObjcClass); while( mlist != NULL ) { while( i < mlist->method_count) { NSLog(@"%@ has %i arguments, which are %i in size", NSStringFromSelector(mlist->method_list[i].method_name),method_getNumberOfArguments(&mlist->method_list[i]) , method_getSizeOfArguments(&mlist->method_list[i])); i++; } i = 0; mlist = class_nextMethodList( ourObjcClass, &iterator ); }
A couple of things are interesting to note here. The number of arguments will be 2 more than what you'd expect, because objc methods have 2 hidden arguments: the pointer to the object, and the name of the selector. Another thing to note is that you MUST include "objc-class.h" in your project and at the top of whatever class you're doing this in, or you will get errors. Check out file://Developer/Documentation/Cocoa/ObjectiveCLanguage-title.html for more information on the ObjC language's features.
swont
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Oct 17, 2003, 07:06 AM
 
This is a nice tip. Thanks!
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:17 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2