Re: Cocoa's custom class delegate conventions
Re: Cocoa's custom class delegate conventions
- Subject: Re: Cocoa's custom class delegate conventions
- From: Sailor Quasar <email@hidden>
- Date: Sat, 14 Jun 2003 04:24:43 -0400
On Saturday, June 14, 2003, at 12:58 AM, Sherm Pendley wrote:
First you should at least verify that your delegate does respond to
the selector (respondsToSelector:) you will invoke.
if ((delegate != nil) && ([delegate
respondsToSelector:@selector(thingWillDoStuff:)) {
[delegate performSelector:@selector(thingWillDoStuff:)
withObject:self];
}
If there are methods that the delegate *must* implement, then you can
declare those methods as part of a formal protocol. You can then
declare the iVar that refers to the delegate as
id<MyDelegateProtocol>, and call the delegate methods directly,
without having to route them through performSelector:. A protocol
would also allow you to simply send the would-be delegate a single
conformsToProtocol: message in setDelegate: instead of a series of
respondsToSelector: messages scattered about your code.
For that matter, once you've confirm that [delegate
respondsToSelector:@selector(thingWillDoStuff:)], why in the world
can't you simply then call [delegate thingWillDoStuff:self] directly?
It's an id after all, and I believe one of the rules of ids is that you
can send any selector to them that they recognize.
-- Sailor Quasar, just another player in The World
"Come with me in the twilight of the summer night for awhile"
Email: email@hidden
_______________________________________________
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.