• 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
NSMethodSignature for Protocol
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSMethodSignature for Protocol


  • Subject: NSMethodSignature for Protocol
  • From: petite_abeille <email@hidden>
  • Date: Thu, 13 Mar 2003 16:53:01 +0100

Hello,

Here is a little Protocol category which creates the relevant NSMethodSignature for a given selector. Which can be handy when using forwardInvocation: in conjunction with a Protocol.

Mandatory usage example:

Protocol* aProtocol = @protocol(NSObject);
NSMethodSignature* aSignature = [aProtocol methodSignatureForSelector: @selector(performSelector:withObject:withObject:)];

And here is the code for your entertainment:

typedef struct objc_method_description_list* ObjCMethodDescriptionList;
typedef struct objc_method_description* ObjCMethodDescription;

@interface NSMethodSignature(RuntimeAdditions)

+ (id) signatureWithObjCTypes: (char*) objCTypes;

@end

@implementation Protocol(RuntimeAdditions)

- (ObjCMethodDescriptionList) _instanceMethodDescriptionList
{
return instance_methods;
}

- (NSMethodSignature*) methodSignatureForSelector: (SEL) aSelector
{
if ( aSelector != NULL )
{
ObjCMethodDescriptionList aList = [self _instanceMethodDescriptionList];

if ( aList != NULL )
{
unsigned int count = aList -> count;
unsigned int index = 0;

for ( index = 0; index < count; index++ )
{
ObjCMethodDescription aMethodDescription = &aList -> list[index];
SEL aProtocolSelector = aMethodDescription -> name;

if ( aSelector == aProtocolSelector )
{
char* aType = aMethodDescription -> types;

if ( aType != NULL )
{
return [NSMethodSignature signatureWithObjCTypes: aType];
}
}
}

return nil;
}

[NSException raise: NSInvalidArgumentException format: @"Protocol.methodSignatureForSelector: no instance methods found."];
}

[NSException raise: NSInvalidArgumentException format: @"Protocol.methodSignatureForSelector: null selector."];

return nil;
}

@end

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.

  • Prev by Date: Re: WSMethodInvocationInvoke & Basic Authentication
  • Next by Date: Get fontinfo from PDF
  • Previous by thread: Re: WSMethodInvocationInvoke & Basic Authentication
  • Next by thread: Get fontinfo from PDF
  • Index(es):
    • Date
    • Thread