Place the @SuppressWarnings annotation at the declaration of the class, method, field, or local variable that uses a deprecated API. The @SuppressWarnings options are: @SuppressWarnings("deprecation") — Suppresses only the ordinary deprecation warnings.
Navigate to Issue Navigator. In the Issue navigator, type "deprecated" in the below filter. Now you will be able to see all (and only) deprecated Buildtime warnings.
Deprecation warnings are a common thing in our industry. They are warnings that notify us that a specific feature (e.g. a method) will be removed soon (usually in the next minor or major version) and should be replaced with something else.
Since I yet can not add a comment to the @samiq post, I think I will expand it. Input mentioned directive before a function / method in which you use deprecated stuff. Then you can restore the previous setting after the definition of the function end:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- (void) methodUsingDeprecatedStuff {
//use deprecated stuff
}
#pragma GCC diagnostic pop
Clang provides a nice feature that makes the "restore" step in the @manicaesar post independent of the initial warning state:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void) methodUsingDeprecatedStuff {
//use deprecated stuff
}
#pragma clang diagnostic pop
To quote the Clang manual:
In addition to all of the functionality provided by GCC's pragma, Clang also allows you to push and pop the current warning state. This is particularly useful when writing a header file that will be compiled by other people, because you don't know what warning flags they build with.
Try -Wno-deprecated-declarations
, or its corresponding setting in Xcode, GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS
(pro tip: just type in "deprecated" in the build settings to find the specific setting for this warning).
Current versions of Xcode (e.g. Xcode 9.2):
Ancient versions of Xcode (e.g. Xcode 2.x, 3.x):
Since we tend to need to support older OSes, but pay attention to our warnings, I wanted a tidier way to do this. I put this together, inspired by some Mozilla code:
#define SILENCE_DEPRECATION(expr) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
expr; \
_Pragma("clang diagnostic pop") \
} while(0)
#define SILENCE_IOS7_DEPRECATION(expr) SILENCE_DEPRECATION(expr)
#define SILENCE_IOS8_DEPRECATION(expr) SILENCE_DEPRECATION(expr)
This allows you to do the following:
SILENCE_IOS7_DEPRECATION(return [self sizeWithFont:font constrainedToSize:size]);
It also works with blocks of code:
SILENCE_IOS7_DEPRECATION(
view = [[MKPolylineView alloc] initWithPolyline:self];
view.lineWidth = self.lineWidth;
view.strokeColor = self.color;
);
Also, when you do drop support for pre-iOS 7 devices, you can easily search through the code to find the deprecated usages to fix.
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