Not sure exactly where to post this but I thought I would start here. We have a Framework for iOS which has a delegate protocol defined. We have decided that one of the methods needs to start sending back a new parameter.
Say you have this protocol
@protocol MyProtocol <NSObject>
-(void) actionWithLink:(NSString *)link;
@end
We now want this protocol but we don’t want to force the end developer to have to change their code right way:
@protocol MyProtocol <NSObject>
-(void) actionWithLink:(NSString *)link type:(NSString*)type;
@end
What we came up with was:
@protocol MyProtocol <NSObject>
-(void) actionWithLink:(NSString *)link DEPRECATED_ATTRIBUTE ;
-(void) actionWithLink:(NSString *)link type:(NSString*)type;
@end
Unfortunately it looks like you can’t actually deprecate a protocol method (many google searches have said this)
So we though of creating a second protocol based on the first:
DEPRECATED_ATTRIBUTE
@protocol MyProtocol <NSObject>
@optional // do this because otherwise you still have to implement the deprecated method
-(void) actionWithLink:(NSString *)link;
@end
@protocol MyProtocol2 <MyProtocol>
-(void) actionWithLink:(NSString *)link type:(NSString*)type;
@end
Unfortunately that only tells us that we are implementing an old protocol. When you switch the name to MyProtocol2 it doesn’t warn you that you should remove the old method.
Another approach turns things upside down:
@protocol MyProtocol2 <NSObject>
@optional // do this because otherwise you still have to implement the deprecated method
-(void) actionWithLink:(NSString *)link;
-(void) actionWithLink:(NSString *)link type:(NSString*)type;
@end
DEPRECATED_ATTRIBUTE
@protocol MyProtocol <NSObject>
-(void) actionWithLink:(NSString *)link;
@optional
-(void) actionWithLink:(NSString *)link type:(NSString*)type;
@end
That didn’t work either. So I am left with creating 2 protocols and deprecating one of them:
@protocol MyProtocol2 <NSObject>
-(void) actionWithLink:(NSString *)link
type:(NSString*)type;
@end
DEPRECATED_ATTRIBUTE
@protocol MyProtocol <NSObject>
-(void) actionWithLink:(NSString *)link;
@end
Now I run into the problem that I have defined the setDelegate call as:
-(void)setDelegate:(id<MyProtocol>)delegate;
And you can’t add a new method with just a change in the type.
Help!
Jim Adams
SAS Customer Intelligence Mobile Architect
|