Problem description
In our project, often use a lot of third-party code, the code may be very complex, we do not dare to change them, but the author has stopped updating, when the SDK upgrade or the compiler upgrade, these legacy code may appear many warnings, then we have no way to remove these annoying warnings, Otherwise a project hundreds of warning, you look at how all the unpleasant. How do we get rid of the warning?
1. The most direct, one-time, safest way to directly find the code of the warning, instead of warning. This is the safest way.
However, it has a problem, that is, when many of our files have this type of warning, we need to change a lot of source code, for not we write the source code, it is possible to update at any time, we this way, obviously not very desirable.
2. Use the macros provided by the compiler to operate, this way in our project will be a lot of see:
#pragma clang diagnostic push#pragma clang diagnostic ignored "-wdeprecated-declarations" / / write in the middle of the code, will not be prompted by the compiler-wdeprecated-declarations type of warning dispatch_queue_tcurrentqueue =dispatch_get_ Current_queue (); #pragma clang diagnostic pop
The problem of this way, the same as the first, but also to modify the implementation of the source code, for the third party, we certainly do not want to change it, especially some update very frequent third parties, the general warning appears shortly after the author updated, we do this in this operation, it seems wasteful. and in When adding arm64 support, it's a bit of a time-consuming effort to have hundreds of of some kinds of warnings.
For example our project, opened the arm64, and then compiled:
3. Close a warning of a specified type for a specified file
Here, take a concrete project. For example, we have a file in our project Presencepacket
In fact, it is simple to close some type of warning for a specified file, as if we had previously added arc support to a file or not supported, adding ignore/show some type warning
Double-click the file to add-wno-shorten-64-to-32 (this key is to let the compiler ignore implicit conversion loses integer precision: ' Nsinteger ' (aka ' Long ') To ' int32_t ' (aka ' int ') warning)
After the add is finished, then compile, then the implicit in the Presencepacket file conversion loses integer precision: ' Nsinteger ' (aka ' Long ') to ' int32_t ' (aka ' I NT ') warning is not, is not very simple, very convenient.
This way, has been greatly reduced the workload, only need to add-wno-shorten-64-to-32 in the compilation of the specified file. So is there any way that the compiler can ignore the warnings of the specified type throughout the project?
4. Turn off warnings for the specified type in the project
This is the simplest, the project target has an other Warning Flags
Where to add-wno-shorten-64-to-32
Re-compile, haha, the entire file in the implicit conversion loses integer precision: ' Nsinteger ' (aka ' Long ') to ' int32_t ' (aka ' int ') warning all disappeared!! !!
5. You may be wondering how the above-wno-shorten-64-to-32, how I know implicit conversion loses integer precision: ' Nsinteger ' (aka ' Long ') to ' int32_t ' (aka ' int ') warning is the-wno-shorten-64-to-32 type? Here, in fact, do not need to remember, when the project has this type of warning when
In the warning window, on a warning, we right-click, display the right-click menu, select the Reveal in Log
It will show
Note that [-wshorten-64-to-32], in this parenthesis, is the type of this warning-W is the prefix, this prefix indicates the warning to open this type if we are to turn off some type of warning, we want to switch-W to-wno-
This will get the-wno-shorten-64-to-32.
Postscript:
For third parties we introduce with cocoapod, we can add a sentence to the Podfile file inhibit_all_warnings! The project to have pods does not show any warnings, such as
Link_with'Secondhousebrokerapp','secondhousebrokercom'Platform:ios,'6.0'inhibit_all_warnings!pod'Cocoaasyncsocket'pod'reachability'pod'PROTOBUFOBJC'pod'Sdwebimage'pod'FMDB'pod'Gpuimage'pod'Cxphotobrowser'pod'Cocoalumberjack'
Also, the above method is suitable for other types of warnings!!!
Transferred from: http://www.cocoachina.com/ios/20141218/10678.html
How to get rid of some kind of warning in Xcode project