• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
What is the best way to deprecate a protocol method?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What is the best way to deprecate a protocol method?


  • Subject: What is the best way to deprecate a protocol method?
  • From: Jim Adams <email@hidden>
  • Date: Thu, 23 Mar 2017 20:49:33 +0000
  • Thread-topic: What is the best way to deprecate a protocol method?

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



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: What is the best way to deprecate a protocol method?
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: How do I adjust a NSSplitView(Controller) pane proportions in Interface Builder?
  • Next by Date: Re: What is the best way to deprecate a protocol method?
  • Previous by thread: Re: How do I adjust a NSSplitView(Controller) pane proportions in Interface Builder?
  • Next by thread: Re: What is the best way to deprecate a protocol method?
  • Index(es):
    • Date
    • Thread