DEPRECATED_ATTRIBUTE is a macro, it is defined as:
/* * only certain compilers support __attribute__((deprecated)) */ #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) #define DEPRECATED_ATTRIBUTE __attribute__((deprecated)) #else #define DEPRECATED_ATTRIBUTE #endif
It’s very clear that this macro is actually using
__attribute__((deprecated)) which is “One of the best (but little known) features of GNU C, which allows a developer to attach characteristics to function declarations to allow the compiler to perform more error checking”. To use it with GNU C, you need to set
-Wall option to compiler. /via Steve Friedl
When and where to use
OK, this macro is so useful, when and where should I use it?
First of all, this can be used on Objective-C method and properties.
Second, let’s see some common scenes.
- To deprecate a method in a widely used library. If you are writing an open-source library and you don’t want to crash your user’s app, this macro is definitely your best friend.
- To replace a method with new a new one. Xcode’s refactoring is not so good on adding/deleting a parameter to a method. This macro can help you a lot.
Add this macro, compile it , find the warnings, fix them, ship your app! That’s it, as simple as you can image.