• 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: default method on an object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: default method on an object


  • Subject: Re: default method on an object
  • From: Brian Hill <email@hidden>
  • Date: Fri, 6 Jul 2001 12:31:22 -0500

On Friday, July 6, 2001, at 11:24 AM, Jeff Medcalf wrote:

Is there a way in Cocoa, to declare a method, such that a message to the object containing that method, which does not find a method to invoke, will invoke that method instead. In other words, if I have a class with 1 method, myMethod:, and it gets a message like [myObject someOtherMethod:], is there a way that I can have myMethod: invoked instead of an error being generated?

Thanks

This is a pretty good description of what the forwardInvocation: message does.
In a nutshell, you need to override forwardInvocation:, reset the invocation's selector to the one you want to get invoked, and then invoke the invocation (clumsy sentence...).

I've found that you may also need to override 'respondsToSelector:' and methodSignatureForSelector: in some cases (well, the case I needed to do this was to forward the message to an embedded scripting engine, so this may not be necessary if the object actually responds to the substituted selector). If you need to change the target of the invocation, you may need to do this as well.

Brian

email@hidden http://personalpages.tds.net/~brian_hill
___________________________________________________________
"Why? I came into this game for adventure - go anywhere, travel
light, get in, get out, wherever there's trouble, a man alone.
Now they've got the whole country sectioned off and you can't
move without a form. I'm the last of a breed."
-- Archibald "Harry" Tuttle, Rogue HVAC Repairman
___________________________________________________________


References: 
 >default method on an object (From: Jeff Medcalf <email@hidden>)

  • Prev by Date: Re: default method on an object
  • Next by Date: Re: Let's hope XP doesn't keep this "one-up" on OS X! [OT]
  • Previous by thread: Re: default method on an object
  • Next by thread: Re: default method on an object
  • Index(es):
    • Date
    • Thread