How to manually deprecate members
You can use the Available tag, for example :
@available(*, deprecated)
func myFunc() {
// ...
}
Where * is the platform (iOS, iOSApplicationExtension, macOS, watchOS, tvOS, * for all, etc.).
You can also specify the version of the platform from which it was introduced
, deprecated
, obsoleted
, renamed
, and a message
:
@available(iOS, deprecated:6.0)
func myFunc() {
// calling this function is deprecated on iOS6+
}
Or
@available(iOS, deprecated: 6.0, obsoleted: 7.0, message: "Because !")
func myFunc() {
// deprecated from iOS6, and obsoleted after iOS7, the message "Because !" is displayed in XCode warnings
}
If your project targets multiple platforms, you can use several tags like so :
@available(tvOS, deprecated:9.0.1)
@available(iOS, deprecated:9.1)
@available(macOS, unavailable, message: "Unavailable on macOS")
func myFunc() {
// ...
}
More details in the Swift documentation.
How to mark a method as obsolete or deprecated?
The shortest way is by adding the ObsoleteAttribute
as an attribute to the method. Make sure to include an appropriate explanation:
[Obsolete("Method1 is deprecated, please use Method2 instead.")]
public void Method1()
{ … }
You can also cause the compilation to fail, treating the usage of the method as an error instead of warning, if the method is called from somewhere in code like this:
[Obsolete("Method1 is deprecated, please use Method2 instead.", true)]
How to mark functions as `@deprecate`d?
Imagine you have this method as part of the public API of your library in version 1:
# v1.0.0
mult3(x::Int) = 3x
In version 2, you'd like to stop supporting mult3
(which is a breaking change). But the same feature will still be available using a more general method:
# v2.0.0
mult(x, y) = x * y
Users of version 1 are used to using mult3
, which means that their code will break when they will update to v2. Therefore, you might want to release an intermediate version in the v1.x family, where mult3
exists but is deprecated and implemented in terms of mult
:
# v1.1 - transition
# This is the new API for v2
mult(x, y) = x*y
# The old API is still supported, but deprecated and implemented using the old one
@deprecate mult3(x::Int) mult(3, x)
# The above is more or less equivalent to defining
# function mult3(x::Int)
# # print an error message is `--depwarn` has been set
# return mult(3, x)
# end
The v1 API is not broken in late v1.x versions, but users calling deprecated methods will see the following kind of messages to help them transition to the newer v2 API:
julia> mult3(14)
┌ Warning: `mult3(x::Int)` is deprecated, use `mult(3, x)` instead.
│ caller = top-level scope at REPL[3]:1
└ @ Core REPL[3]:1
42
(but starting with Julia 1.5, the warning will only be shown if --depwarn=yes
has been provided in Julia's command line or if it appears in a test suite run by Pkg.test()
)
Alternatively, and as mentioned in comments, you may want to leave the old implementation around, simply warning users when they call it. To this end, you can use Base.depwarn
directly:
# v1.1 - transition
# This is the new API for v2
mult(x, y) = x*y
# The old API is still supported, but deprecated
# It is implemented by itself:
function mult3(x)
Base.depwarn("`mult3(x)` is deprecated, use `mult(3,x)` instead.", :mult3)
return 3x
end
When --depwarn=yes
has been provided in Julia's command line, this produces the same kind of warning as @deprecate
:
julia> mult3(14)
┌ Warning: `mult3(x)` is deprecated, use `mult(3,x)` instead.
│ caller = top-level scope at REPL[4]:1
└ @ Core REPL[4]:1
42
Starting with Julia 1.6, depwarn
will accept a keyword argument to force warning emission even when users haven't asked for them with --depwarn=yes
:
julia> Base.depwarn("Foo is deprecated", :foo, force=true)
┌ Warning: Foo is deprecated
│ caller = ip:0x0
└ @ Core :-1
Is it possible to mark something as deprecated in typescript?
You can use JSDoc comments to mark deprecated code:
/**
* @deprecated The method should not be used
*/
export const oldFunc = () => {}
Also, this eslint rule can look through the deprecated methods and warn about their usage.
How should I mark a method as obsolete in JS?
There are a couple of things you can do in a transition period.
- Add the
@deprecated
JSDoc flag. - Add a console warning message that indicates that the function is deprecated.
A sample:
/**
* @deprecated Since version 1.0. Will be deleted in version 3.0. Use bar instead.
*/
function foo() {
console.warn("Calling deprecated function!");
bar();
}
How do I deprecate an attribute in a Moose based class
Here's another way to do it! Use MooseX::Deprecated :-)
with "MooseX::Deprecated" => {
attributes => [ "id_generator" ],
};
I wrote MooseX::Deprecated inspired by my previous answer to this question. It encapsulates the application of method modifiers, checking init_args, fiddling with %Carp::Internal
and warnings::enabled
, all into one tidy little package.
How to deprecate function when return type changes c++
Although the solution will force you to change your function names, but it'll be a compromise between your old users and your new ones.
So - rename the old foo
into deprecatedFoo
and your new foo
into foo2
(or anything you want). Then, in the header file you include with your library, you can simply:
#define deprecatedFoo foo
and inside the function itself do:
#warning ("This function is deprecated. Use 'foo2' or change the #define in LINE in file HEADER.")
Users of the old versions won't have to change their code, and will be issued a warning, and the new users will probably listen and change the #define
in order to use the new foo
.
In the next version you'll just delete the old foo
and the define
.
Deprecate old name for class in C++
As said by others, this is very compiler specific. Assuming your classes are defined with the new name. Here is what you can do with GCC and MSVC:
class NewClassA {}; // Notice the use of the new name.
// Instead of a #define, use a typedef with a deprecated atribute:
// MSVC
typedef NewClassA __declspec(deprecated) OldClassA;
// GCC
//typedef NewClassA __attribute__((deprecated)) OldClassA;
int main(){
NewClassA newA;
OldClassA oldA;
}
MSVC yields:
warning C4996: 'OldClassA': was declared deprecated
GCC yields:
warning: 'OldClassA' is deprecated
No warning is emmited for NewClassA newA;
by either compiler.
Related Topics
Uinavigationcontroller "Back Button" Custom Text
How to Use Avfoundation to Crop a Video
Duplicate Symbol Error in Nsmanagedobject Subclass
Swift: Can't Get Nsdate Dateformatter Right
How to Create Custom Mkannotationview and Custom Annotation Title and Subtitle
Exc_Bad_Access When Building Nspredicate
Uitableview Within Uiscrollview Using Autolayout
iOS Blocks and Strong/Weak References to Self
How to Implement Uipageviewcontroller That Utilizes Multiple Viewcontrollers
How to Create a Colored 1X1 Uiimage on the iPhone Dynamically
Xcode 7 Swift 2 Impossible to Instantiate Uiviewcontroller Subclass of Generic Uitableviewcontroller
How to Access File Included in App Bundle in Swift
[Nsobject:Anyobject]' Does Not Have a Member Named 'Subscript' Error in Xcode 6 Beta 6