• 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: method signature from a protocol?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: method signature from a protocol?
      • From: Ondra Cada <email@hidden>
References: 
 >method signature from a protocol? (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Carbon API with carbon
  • Next by Date: Re: method signature from a protocol?
  • Previous by thread: method signature from a protocol?
  • Next by thread: Re: method signature from a protocol?
  • Index(es):
    • Date
    • Thread