• 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: How does Cocoa implement delegate/callback?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How does Cocoa implement delegate/callback?


  • Subject: Re: How does Cocoa implement delegate/callback?
  • From: Chris Hanson <email@hidden>
  • Date: Fri, 15 Nov 2002 00:08:32 -0600

It's fairly simple to use an NSInvocation. Just get a method signature from the target of the invocation, create an invocation using that signature, set the selector, set any arguments, invoke the invocation with the target, and get the return value from it.

The code below is adapted from -[BDKeyValueQualifier evaluateWithObject:] in my BDControl framework:

- (BOOL)sendSelector:(SEL)selector
toTarget:(id)target
withValue:(id)value
{
BOOL result = NO;

if ([target respondsToSelector:selector]) {
NSMethodSignature *signature;
NSInvocation *invocation;

signature = [target methodSignatureForSelector:selector];

invocation = [NSInvocation invocationWithMethodSignature:signature];

[invocation setSelector:selector];

// (Arguments 0 and 1 are self and _cmd, respectively.)

[invocation setArgument:&value atIndex:2];

[invocation invokeWithTarget:target];

[invocation getReturnValue:&result];
}

return result;
}

It assumes that selector is a selector corresponding to a method taking one id argument and returning a BOOL.

-- Chris
_______________________________________________
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.

References: 
 >How does Cocoa implement delegate/callback? (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Gestalt syntax...
  • Next by Date: Re: TIFFRepresentation giving me a tiff WITH an alpha
  • Previous by thread: Re: How does Cocoa implement delegate/callback?
  • Next by thread: Re: How does Cocoa implement delegate/callback?
  • Index(es):
    • Date
    • Thread