On Mar 26, 2013, at 14:14 , Conrad Shultz <conrad_shu...@apple.com> wrote:

> Step #1 in my hypothetical was that in the future a *required* delegate 
> method be added, in which case there would be no -respondsToSelector: check.

1. Your earlier suggestion of having *two* delegate objects would certainly be 
one way of ensuring this couldn't be a problem.

2. If there is to be only one delegate object, the correct way (in terms of 
ensuring compile-time compliance) would be to declare the subclass "delegate" 
property override like this:

        @property (nonatomic) id<TKOutlineViewDelegate> delegate; // making it 
readwrite now

That is, any code setting a delegate would be required to provide one of the 
correct sort. If desirable (and perhaps it would be under the circumstances), 
this could be enforced at run-time by providing overrides, rather than using 
@dynamic:

        - (id<TKOutlineViewDelegate>) delegate {
                id<TKOutlineViewDelegate> delegate = [super delegate];
                if ([delegate conformsToProtocol: @protocol 
(TKOutlineViewDelegate)])
                        return delegate;
                else
                        return nil;
        }

        - (void) setDelegate: (id<TKOutlineViewDelegate>) delegate {
                NSAssert ([delegate conformsToProtocol: @protocol 
(TKOutlineViewDelegate)], @"Boo boo");
                [super setDelegate: delegate];
        }

3. With one delegate object, if there's a legal scenario where some code might 
think that the outline view was merely a NSOutlineView and therefore set a 
delegate that was merely NSOutlineViewDelegate rather than 
TKOutlineViewDelegate, then conformity to TKOutlineViewDelegate is effectively 
optional. It would be incumbent, then, on callers of the TKOutlineViewDelegate  
delegate methods to either check for conformity or to check respondsToSelector, 
even for @required methods.

The correct approach requires knowing the answer to this question: Does 
TKOutlineView *require* TKOutlineViewDelegate conformity, or is it merely 
optional?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to