Re: Cocoa-dev Digest, Vol 3, Issue 1474
Re: Cocoa-dev Digest, Vol 3, Issue 1474
- Subject: Re: Cocoa-dev Digest, Vol 3, Issue 1474
- From: Sam Colombo <email@hidden>
- Date: Wed, 20 Dec 2006 15:14:18 -0600
> In AppKit, Apple generally hand on the notifications to the
> delegates, yes. And also, in general, there is a category on NSObject
> (used as an informal protocol) in every class that delegates methods
> that declares these methods (generally named something like
> NSSomethingDelegateMethods). That's just a convention followed by the
> AppKit developers internally. There's nothing in Objective C that
> enforces this (though it's a good idea to do the same in your code,
> even if just to reduce the surprises others have when they use your
> code).
>
So the bottom line is that there is no sure way to identify what is
delegatable from the supplied headers themselves. You have to depend on the
occasional comments, protocols with "delegate" in their title, and
Notifications (or just look in the documentation) and take it on faith that
they are actually delegatable. I guess I can live with that. (Like I have a
choice. :-)
> There's nothing keeping you from creating your own view class that
> delegates things if you want to. However, one advantage of delegation
> is that you can implement the delegate methods for several views in
> one controller object. That's why delegation /can be/ better than
> subclassing. You don't need a subclass of each view (and for example
> NSTextView *does* delegate some of its tasks) just to implement
> application-specific logic. You can use the standard objects
> unchanged and as-is.
So if I want to make event handling delegatable then I have to override
the NSResponder methods and individually do the (short version):
if(respondsToSelector) doDelegateMethod
else doItHere
Or implement what I surmise the Framework does, which would be to
override forwardInvocation, create a dictionary listing sels for delegatable
methods and default nils, some of which would be replaced by delegate method
sels when setDelegate is called. I assume the dispatcher checks here first
before calling any methods. Am I getting warm?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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