How to get rid of some kind of warning in Xcode project

Source: Internet
Author: User

Xcode warning

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:

12345 #pragma clang diagnostic push#pragma clang diagnostic ignored"-Wdeprecated-declarations"    //写在这个中间的代码,都不会被编译器提示-Wdeprecated-declarations类型的警告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

12345678910111213 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!!!

How to get rid of some kind of warning in Xcode project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.