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:11:33 -0700
On Mar 26, 2013, at 12:58 PM, Chris Tracewell <email@hidden> wrote:
> On Mar 26, 2013, at 12:38 PM, Quincey Morris <email@hidden> wrote:
>
>> 2. Redeclare the "delegate" property:
>>
>> @interface TKOutlineView : NSOutlineView {}
>> @property (nonatomic,readonly) id<TKOutlineViewDelegate> delegate;
>> @end
>>
>> @implementation TKOutlineView
>> @dynamic delegate;
>> …
>> [[self delegate] outlineView:self enterKeyPressedForRow:[self selectedRow]];
>> …
>>
>> The @dynamic statement says "I don't have an implementation of the 'delegate' property in this class, but that's just fine because it's already implemented (in my superclass)".
>
> Aha, success. Thank you - a very elegant and sensible solution.
>
> CT
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>.
This is why I earlier suggested declaring a -customDelegate (or whatever you'd like to call it) property that would not interfere with the expected delegate behavior.
-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