Implementing delegate categories for subclasses

Christiaan Hofman <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
As you all know SL has replaced all informal delegate protocols by  
formal protocols. This gives me some problems when subclassing classes  
that should extend such a protocol. In particular if I want to be able  
to use the same code for both the 10.6 and 10.5 SDK.

The docs recommend implementing empty protocols for the new NS ones  
conditional on using an old SDK (MAC_OS_X_VERSION_MAX_ALLOWED).  
However, I have yet not been able to find any recommendations how best  
to handle subclasses, in particular in this situation.

So would someone on this list have an idea what the best way is to  
handle this situation?

A big problem is the fact that @optional is not supported with the  
10.5 SDK. The only way I can think of is to add it conditionally on  
the SDK, and use an informal protocol for 10.5.

Here are some things I tried. Take as an example an NSTableView  
subclass.


@protocol MYTableViewDelegate <NSTableViewDelegate>
#if MAC_OS_X_VERSION_MAX_ALLOWED  <= MAC_OS_X_VERSION_10_5
@end
@interface NSObject (MYTableViewDelegate)
#else
@optional
// extra delegate methods here
@end

@interface MYTableView : NSTableView {
	// extra ivars here
}
// extra method declarations here
- (id<MYTableViewDelegate>)delegate;
- (void)setDelegate:(id<MYTableViewDelegate>)newDelegate;
@end

@implementation MYTableView
// extra method implementations here
- (id<MYTableViewDelegate>)delegate {
	return (id<MYTableViewDelegate>)[super delegate];
}
- (void)setDelegate:(id<MYTableViewDelegate>)newDelegate {
	[super setDelegate:newDelegate];
}
@end


However, this gives warnings when using the 10.5 SDK when I try to use  
the delegate with my new delegate methods, because the  
MYTableViewDelegate protocol is empty. However, when I don't override  
the -delegate and -setDelegate methods, I get warnings when using the  
10.6 SDK, because the delegate is only conforming to  
NSTableViewDelegate.

So my question is whether I'm doing things right this way, how to do  
it better, and what would be the recommended way to handle this?  
Perhaps we can get some discussion going here that would make some  
recommendations going into the docs.

thanks,
Christiaan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.