I have a couple of methods that I want to deprecate.
I do this with the following:
+(void)myMethod:(NSString*)abc __deprecated;
This works, but how do I add a message? Something like "use methody xyz instead"...
Thanks
You should not edit or remove any existing comments, other than to add the JavaDoc tag or annotation. Deprecated code might still be in use in legacy systems, and developers of those systems need to have access to the documentation that the original developers did in some form.
Use both @Deprecated annotation and the @deprecated JavaDoc tag. The @deprecated JavaDoc tag is used for documentation purposes. The @Deprecated annotation instructs the compiler that the method is deprecated. Here is what it says in Sun/Oracles document on the subject:
Using the annotation causes the Java compiler to generate warnings when the deprecated class, method, or field is used. The compiler suppresses deprecation warnings if a deprecated compilation unit uses a deprecated class, method, or field. This enables you to build legacy APIs without generating warnings.
Also, we can communicate the deprecated status in the documentation as well by using the Javadoc @deprecated tag. 3. Optional Attributes Added in Java 9
As Nicholas Smith mentioned in the comments. The solution is:
__attribute((deprecated("use x method")))
if you want you can also use the less convoluted:
__deprecated_msg("use x method")
I would tend to use this:
__deprecated_msg("use method x instead")
rather than:
__attribute((deprecated("use method x instead")))
They're really the same under the hood, but first one is a bit more clear.
Put this right above the method:
@available(*, deprecated: <#Version#>, message: <#Message#>)
example:
@available(*, deprecated: 11, message: "Use color assets instead")
public struct ColorPaletteItemResource: ColorPaletteItemResourceType {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With