I participated in an iOS App in a version of the minimum support to iOS9.0 system, if the application continues to use some of the API provided by Apple to be abandoned in a higher version, there will be a warning, not allowed to integrate code. Such as stringByAddingPercentEscapesUsingEncoding: method was abandoned in the iOS 9.0. So what if you don’t want to change it (it’s too risky) and you don’t want a warning? You learned that you can use the #pragma declaration to prevent the compiler from issuing warnings.

#pragma clang Diagnostic push #pragma Clang Diagnostic ignored "relevant commands" // Your own code #pragma clang diagnostic popCopy the code

The commands vary depending on the scenario. The commonly used commands are as follows:

  • Warning of unused variable: -wunused-variable
  • Method deprecation warning: -wdeprecated -declarations
  • Cyclic reference warning: -warc -retain-cycles
  • Warning of incompatible pointer types: -wincompatible-pointer-types
  • Memory leak warning: -warc -performSelector-leaks

Such as ignoring method deprecation warnings

#pragma clang diagnostic push #pragma clang diagnostic ignored "-wdeprecated -declarations" #pragma clang diagnostic push #pragma clang diagnostic ignored" -wdeprecated -declarations diagnostic popCopy the code