Re: Custom Delegate - Using _delegate works but not delegate or [self delegate]
Re: Custom Delegate - Using _delegate works but not delegate or [self delegate]
- Subject: Re: Custom Delegate - Using _delegate works but not delegate or [self delegate]
- From: Conrad Shultz <email@hidden>
- Date: Tue, 26 Mar 2013 13:54:42 -0700
On Mar 26, 2013, at 1:40 PM, Quincey Morris <email@hidden> wrote:
> On Mar 26, 2013, at 13:11 , Conrad Shultz <email@hidden> wrote:
>
>> If code expecting an NSOutlineView receives a TKOutlineView instance it may break or behave unexpectedly since it may well try to set a delegate conforming to <NSOutlineViewDelegate> but you have made your class require a delegate conforming to the more specific <TKOutlineViewDelegate>.
>
> Chris's delegate actually implements NSOutlineViewDelegate, doesn't it?
>
> Lee Ann's earlier suggestion of declaring TKOutlineViewDelegate to conform to NSOutlineViewDelegate would prevent any remaining compiler complaints. Thus the final declaration of the protocol would look like:
>
> @protocol TKOutlineViewDelegate <NSObject,NSOutlineViewDelegate>
>
> Would that take care of your concern?
My concern is not a compile-time issue; it's a substitutability issue that may manifest at run-time.
Consider the following hypothetical:
1) A required method is added to <TKOutlineViewDelegate>.
2) A class (say, a view controller) expecting an NSOutlineView is handed a TKOutlineView and sets its delegate to an object conforming to <NSOutlineViewDelegate> but *not* <TKOutlineViewDelegate>. This is valid since TKOutlineView is a subclass of NSOutlineView, and as such should be substitutable anywhere an NSOutlineView is expected.
3) The TKOutlineView then later attempts to send the <TKOutlineViewDelegate> message from #1 above to its delegate.
4) An exception is raised at run-time since the delegate actually conforms to <NSOutlineViewDelegate>, not <TKOutlineViewDelegate>.
Admittedly this is a fairly specific combination of events that may never apply, but I wanted to make sure the OP is aware of it.
-Conrad
_______________________________________________
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