• 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: Using non-id sender in IBAction methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using non-id sender in IBAction methods


  • Subject: Re: Using non-id sender in IBAction methods
  • From: Bill Bumgarner <email@hidden>
  • Date: Mon, 08 Jun 2009 10:53:28 -0700

On Jun 7, 2009, at 6:09 PM, Bryan Henry wrote:
I hope you aren't suggesting that he use assertions in production code - that's much worse practice than specifying a non-id parameter for an action method.

As someone already said, if your action method is specific enough to the type of sender object where specifying it's type keeps you from casting, it's unlikely that you're going to have sender objects of different types.

The best solution is to not care what object sent the action.

Instead, architect your code such that an action can be received at any time and work correctly. Personally, I *never* write *any* code that messages 'sender'.

Then, in your UI management code, enable/disable the various buttons or menu items that might send the action, as appropriate.

If you want to be defensive, check to see if the action should be enabled when the action is received. In production, ignore it. In debugging/development mode, log a message and ignore it because you now know you have a situation where it *should* be disabled, but the user could still cause it to be sent.

b.bum



_______________________________________________

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: 
 >Using non-id sender in IBAction methods (From: Marc Liyanage <email@hidden>)
 >Re: Using non-id sender in IBAction methods (From: Uli Kusterer <email@hidden>)
 >Re: Using non-id sender in IBAction methods (From: Bryan Henry <email@hidden>)

  • Prev by Date: Re: How to detect a click on app's dock icon (when the app is active)?
  • Next by Date: -replaceTextStorage: problem
  • Previous by thread: Re: Using non-id sender in IBAction methods
  • Next by thread: NSOutlineView and tags...
  • Index(es):
    • Date
    • Thread