How to remove some warning Implicit conversion loses integer precision: & #39; NSInteger & #39; (aka & #39; long & #39 ;) to & #39; int32, nsinteger

Source: Internet
Author: User

How to remove some type of warning in Xcode project Implicit conversion loses integer precision: 'nsinteger '(aka 'long') to 'int32, NSInteger
Problem description in our project, we usually use a large number 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 or compiler is upgraded, there may be many warnings for these legacy codes. 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. the most direct, permanent, and secure method is to directly find the warning code, instead of 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 a lot in our project # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wdeprecated-declarations" // code written in the middle, will not be prompted by the compiler-Wdeprecated-declarations type warning
Dispatch_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 the warning of a specified type of 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. Close the Warning of the specified type in the project. 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 close some type of warning, we need to replace-W with-Wno-so that we can get-Wno-shorten-64-to-32.


Note: 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 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'
In addition, the above method is also suitable for other types of warnings !!!
Reference http://oleb.net/blog/2013/04/compiler-warnings-for-objective-c-developers/http://amattn.com/p/better_apps_clang_weverything_or_wall_is_a_lie.htmlhttp://stackoverflow.com/questions/16384530/clang-in-xcode-start-with-weverything-and-manually-disable-particular-warninhttp://adoptioncurve.net/archives/2013/02/selectively-disabling-warnings-with-xcode-compiler-flags/

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.