• 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: Abusing targetForAction: with non-action selectors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Abusing targetForAction: with non-action selectors


  • Subject: Re: Abusing targetForAction: with non-action selectors
  • From: Dave Dribin <email@hidden>
  • Date: Mon, 15 Sep 2008 18:44:50 -0500

On Sep 15, 2008, at 6:30 PM, Julien Jalon wrote:
It's not safe... once the target is found (using respondsToSelector:, you're right), the action is performed with:
[target performSelector:actionSelector withObject:sender];


which means that anything but an object as a sender will potentially crash.

The only safe thing you can image is to have an action selector with no paramater at all.

I'm not actually performing the action, just getting the target, and then calling the method myself, kinda like a delegate:


id target = [NSApp targetForAction:@selector(notReallyAnAction:withArgument:)];
if (target != nil)
{
int returnValue = [target notReallyAnAction:foo withArgument:bar];
// Do something with returnValue
}


-Dave

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Abusing targetForAction: with non-action selectors (From: Dave Dribin <email@hidden>)
 >Re: Abusing targetForAction: with non-action selectors (From: "Julien Jalon" <email@hidden>)

  • Prev by Date: Re: Abusing targetForAction: with non-action selectors
  • Next by Date: Re: Abusing targetForAction: with non-action selectors
  • Previous by thread: Re: Abusing targetForAction: with non-action selectors
  • Next by thread: Re: Abusing targetForAction: with non-action selectors
  • Index(es):
    • Date
    • Thread