Re: method signature from a protocol?
Re: method signature from a protocol?
- Subject: Re: method signature from a protocol?
- From: petite_abeille <email@hidden>
- Date: Sat, 13 Jul 2002 16:22:14 +0200
On Saturday, July 13, 2002, at 04:06 , Ondra Cada wrote:
Subject says it all: anybody knows how to obtain an NSMethodSignature
for
a given protocol and selector?
I thought this should be a piece of cake, but can't find a solution?
Thanks for any clue,
Try something like:
@implementation Protocol(SZRuntimeAdditions)
- (ObjCMethodDescriptionList) _classMethodDescriptionList
{
return class_methods;
}
- (ObjCMethodDescriptionList) _instanceMethodDescriptionList
{
return instance_methods;
}
@end
To get the ObjCMethodDescriptionList:
typedef struct objc_method_description_list* ObjCMethodDescriptionList;
typedef struct objc_method_description* ObjCMethodDescription;
And then get a list of methods
+ (NSSet*) _protocolMethodsWithList: (ObjCMethodDescriptionList) aList
{
if ( aList != NULL )
{
unsigned int count = aList -> count;
NSMutableSet* aSet = [NSMutableSet setWithCapacity: count];
unsigned int index = 0;
for ( index = 0; index < count; index++ )
{
ObjCMethodDescription aMethodDescription = &aList -> list[index];
SEL aSelector = aMethodDescription -> name;
if ( aSelector != NULL )
{
NSString* aSelectorName = [NSString stringWithCString:
sel_getName(aSelector)];
char* aType = aMethodDescription -> types;
if ( aType != NULL )
{
NSString* aSignature = [NSString stringWithCString: aType];
NSDictionary* aDictionary = [NSDictionary
dictionaryWithObjectsAndKeys: aSignature, aSelectorName, nil];
[aSet addObject: aDictionary];
}
}
}
if ( [aSet count] > 0 )
{
return aSet;
}
}
return nil;
}
Cheers,
PA.
_______________________________________________
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.