I need to deprecate a single method in objective-c protocol. On normal class/instance methods I add __attribute__ ((deprecated));
after declaration.
It seem
Although the answers here provide some very good information, they are outdated. Starting with Xcode 5.0 and LLVM 5.0 it looks like deprecation warnings for Objective-C protocol methods are recognized. When implementing the method, Xcode 5 flags it:
Warning: Implementing deprecated method
Here are the steps I used to produce a deprecation warning for the implementation of a deprecated protocol method:
Mark the protocol method as deprecated using __deprecated
. From the new SDK 7.0 documentation:
__deprecated causes
the compiler to produce a warning when encountering code using the deprecated functionality.__deprecated_msg()
does the same, and compilers that support it will print a message along with the deprecation warning. This may require turning on such warning with the-Wdeprecated
flag.__deprecated_enum_msg()
should be used on enums, and compilers that support it will print the deprecation warning.
#define __deprecated __attribute__((deprecated))
To deprecate your method, do something like this:
- (void)aDeprecatedProtocolMethod __deprecated;
This alone should be enough for Xcode to display a deprecation warning. However, you should follow the next few steps (knowing that Xcode can be very finicky at times) to ensure the warning displays.
Add a documentation comment with a deprecation warning tag. See the code example below to learn how:
/** Describe the method here - what does it do, how does it work, etc. Very brief.
@deprecated This delegate method is deprecated starting in version 2.0, please use otherMethodNameHere:withAnExtraParameter: instead. */
- (void)aDeprecatedProtocolMethod __deprecated;
Clean the project (⌘+⇧+K) and then Build the project (⌘+B) - just because Xcode can be funky sometimes.
I'm not 100% sure when or where this feature was introduced (maybe with SDK 7.0 and 10.9, or Xcode 5.0 / 5.0.1, or with LLVM 5.0) - but it works nonetheless.