Re: Using non-id sender in IBAction methods
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