Re: Question on cocoa style: value for (id)sender parameter
Re: Question on cocoa style: value for (id)sender parameter
- Subject: Re: Question on cocoa style: value for (id)sender parameter
- From: Shawn Erickson <email@hidden>
- Date: Mon, 24 Jan 2005 13:04:32 -0800
On Jan 24, 2005, at 12:24 PM, Matt Gillette wrote:
Hi,
I have a question about the difference between these two lines (I've
seen both styles in tutorials):
[aSheet orderOut:NULL];
[aSheet orderOut:self];
Is there any advantage to null/nil versus self? What is the sender
variable used for? I'm not just asking about orderOut, but all cocoa
interface methods that take an (id)sender and seem to do nothing with
it.
Such methods are following the target-action paradigm...
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CommunicateWithObjects/Articles/TargetAction.html>
In those cases that you are implementing an active method and don't
need sender simply ignore it.
When sending an action message you should either supply it with an
object the likely provides the methods it would be expecting to have
existing (i.e. expecting a subclass of NSControl) or specify nil.
Anyway often you can get away with supplying nil or even self when in
doubt. If it wants something that you are not supplying you should see
exceptions logged when you test things.
FYI use nil instead of NULL since the former is used to imply no object
in Objective-C while the later implies an invalid pointer.
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden