Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding comment to deprecated method

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

like image 871
Joseph Avatar asked Mar 19 '13 09:03

Joseph


People also ask

Can I edit or remove deprecated comments in Java?

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.

How to deprecate a method in Java?

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:

What is the use of deprecation annotation in Java?

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.

How to communicate the deprecation status in the documentation?

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


3 Answers

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")
like image 107
Joseph Avatar answered Sep 19 '22 12:09

Joseph


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.

like image 35
MrJre Avatar answered Sep 19 '22 12:09

MrJre


- FOR SWIFT CODE:

Put this right above the method: @available(*, deprecated: <#Version#>, message: <#Message#>)

example:

@available(*, deprecated: 11, message: "Use color assets instead")
public struct ColorPaletteItemResource: ColorPaletteItemResourceType {
    ...
}
like image 31
Mojtaba Hosseini Avatar answered Sep 22 '22 12:09

Mojtaba Hosseini