• 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: -methodForSelector: doesn't fail when it should
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -methodForSelector: doesn't fail when it should


  • Subject: Re: -methodForSelector: doesn't fail when it should
  • From: Chris Kane <email@hidden>
  • Date: Thu, 5 Dec 2002 13:46:57 -0800

Found this back in the archives, which didn't seem to have a response... so for the record:

What is being returned for the unknown selector is the pointer to an internal function in the ObjC runtime, _objc_msgForward(). This is basically how forwarding works -- you can send unknown selectors to an object, and if it implements the forwarding hooks, it can handle them in whatever way it likes. The "implementation" function for this is _objc_msgForward(), which starts the invocation of the forwarding hooks on the object. When you send an unknown method to an object, the runtime returns the pointer to _objc_msgForward() to itself when it does the IMP lookup, in the same way you are getting it from methodForSelector:. The runtime then invokes whatever IMP it gets, and you can use this IMP from methodForSelector: in the same way as any IMP.

Note that _objc_msgForward() is a private function, should not be called directly, and the symbol should not be referred to directly either, as the name of the function may change in future releases, and then your program wouldn't work.

Chris Kane
Cocoa Frameworks, Apple


On Monday, September 23, 2002, at 04:32 PM, Andrew Duncan wrote:

Cocoa docs say that calls to -methodForSelector: will cause a
runtime error if the specified selector is not handled. But I can
call [[NSObject new] methodForSelector:@selector(glog)] and get an
apparently valid pointer back. It's in the same memory range as the
result I get back from asking about a valid selector like self.

Apparently even though "glog" doesn't appear as a method name anywhere, it gets a valid SEL pointer set up. But that's a side-issue. Surely I shouldn't get a valid result from -methodForSelector:. What's up? How do I detect failure, apart from checking first with -respondsToSelector:?
_______________________________________________
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.
_______________________________________________
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: runtime error using NSArray with NSButton
  • Next by Date: Re: Subclassing NSWindowController
  • Previous by thread: Re: runtime error using NSArray with NSButton
  • Next by thread: Accessing item elements in Applescript
  • Index(es):
    • Date
    • Thread