scenario

The thing is, today I wanted to deal with the warning that I got after using apple’s deprecated method in the project, which is a piece of code like this. It’s pathetic for iOS6. I know, you don’t say 5555, look at the deprecated first

If you want to adapt to a lower version, there should be plenty of warnings like this. Every time I Build, it says to me: I love it when you hate me and can’t get rid of me. My temper, catch the version for a long time, not easy to empty, must kill in fact, a lot of things are already a solution, we need to find it

Code block handling

BOOL is_iOS6 = [[[UIDevice currentDevice] systemVersion] floatValue] < 7.0f;
if (is_iOS6) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    label.textAlignment = UITextAlignmentCenter;
#pragma clang diagnostic pop
}
Copy the code

It’s a simple solution, but I was wondering who was the first to discover “-wdeprecated -declarations” and if there are any other warnings, I searched again. Click on the warning and right-click Reveal In Log to see the details of the warning

The -wdeprecated -declarations in parentheses is the information we want to get

If you find the keyword, it will be easy. If you know that you can’t dry the warning, you can hide it in this way.

A common format

#pragma Clang Diagnostic #pragma Clang Diagnostic #pragma Clang Diagnostic #pragma Clang Diagnostic #pragma Clang diagnostic #pragma Clang diagnostic #pragma Clang diagnostic #pragma Clang diagnostic #pragma Clang diagnostic #pragma Clang diagnostic #pragma Clang diagnosticCopy the code

However, sometimes in a file, there are many such warnings that are repeated, often in third-party libraries, which is too cumbersome to change one by one, so it is possible to hide all such warnings from a single file.

File processing

Set Compiler Flags for a file in Compile Sources

The resulting warning is -wdeprecated -declarations and should be changed to -wno-deprecated -declarations

All such errors are in the form of -w error messages. We need to replace -w with -wno – to tell the compiler that the file is no longer warning of this error. We can add more

This is to hide the whole file of the warning, sometimes we do not want to see this kind of project, one by one setting is also very tired, so we can also handle the project

Engineering process

In the PROJECT -> Build Settings -> Apple LLVM 6.1 – Custom Complier Flags column set Other Warning Flags

From: my.oschina.net/joanfen/blo…