How can I remove some type of warning in the Xcode project and the xcode project warning?

Source: Internet
Author: User

How can I remove some type of warning in the Xcode project and the xcode project warning?
 

XCode warning

 

Problem description

In our projects, we usually use a large number of third-party code, which may be complicated and we do not dare to change them. However, the author has stopped updating the Code. After the sdk upgrade or compiler upgrade, there may be a lot of warnings for these legacy codes, so is there a way to remove these annoying warnings? Otherwise there may be hundreds of warnings for a project. Why are you upset. How can we remove the warning?

1. In the most direct, permanent, and secure way, find the warning Code directly and change it to no warning. This method is the safest.

But it has a problem: when many of our files have this type of warning, we need to change a lot of source code. For the source code that is not written by us, it may be updated at any time. Obviously, this method is not desirable.

2. Use the macro provided by the compiler for operations. This method will be seen in many projects:

12345 #pragma clang diagnostic push#pragma clang diagnostic ignored"-Wdeprecated-declarations"    // The code written in the middle won't be warned by the compiler-Wdeprecated-declarations typedispatch_queue_tcurrentQueue =dispatch_get_current_queue();#pragma clang diagnostic pop

The problem with this method is similar to that of the first one. We certainly don't want to modify the source code for third parties, especially third parties with frequent updates, the author updated the general warning shortly after it appeared. We are doing this here, which seems to be a waste. when adding the support for arm64, there are hundreds of warnings of some type, which is quite time-consuming and labor-consuming!

For example, in our project, we open arm64 and then compile:

3. disable a specified type of warning for a specified file

Here, let's take a specific project. For example, we have a file PresencePacket in our project.

In fact, it is very easy to disable some type of warning for a specified file, just as we used to add or ignore/display some type of warning when adding ARC support or not support for a file.

Double-click the file and add-Wno-shorten-64-to-32 in it (the key is to let the compiler ignore Implicit conversion loses integer precision: 'nsinteger '(aka 'long ') to 'int32 _ t' (aka 'int') Warning)

After adding the package, compile it again. In the PresencePacket file, the Implicit conversion loses integer precision: 'nsinteger '(aka 'long') to 'int32 _ t' (aka 'int ') the warning is gone. Is it very simple and convenient.

This method has greatly reduced the workload, just need to add-Wno-shorten-64-to-32 In the compilation of the specified file. is there any way for the compiler to ignore the specified type of warning in the entire project?

4. Disable warnings of the specified type in the project

This is the simplest. The target of the project has an Other Warning Flags.

Add-Wno-shorten-64-to-32 in

Re-compile. Haha, Implicit conversion loses integer precision in the entire file: 'nsinteger '(aka 'long') to 'int32 _ t' (aka 'int ') warning All disappears !!!!

5. you may be wondering how the above-Wno-shorten-64-to-32 came from, how do I know Implicit conversion loses integer precision: 'nsinteger '(aka 'long ') to 'int32 _ t' (aka 'int') Warning is-Wno-shorten-64-to-32 type? In this case, you do not need to remember this type of warning.

In the warning window, right-click a warning and select Reveal in Log from the context menu.

The

Note that the [-Wshorten-64-to-32] In this bracket is the type of this warning-W is the prefix, this prefix indicates opening this type of warning. If we want to disable a type of warning, replace-W with-Wno-

So we get the-Wno-shorten-64-to-32.

Postscript:

For third parties we introduced using cocoapod, we can add an inhibit_all_warnings in the podfile file! The project to be pod does not display any warning, such

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'

In addition, the above method is also suitable for other types of warnings !!!

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.