Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to remove a certain type of warning from the Xcode project. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Problem description

In our project, usually use a lot of third-party code, the code may be very complex, we dare not change them, but the author has stopped updating, when the sdk upgrade or compiler upgrade, these legacy code may appear a lot of warnings, so we have no way to remove these annoying warnings, otherwise a project hundreds of warnings, you do not look happy. How do we get rid of the warning?

1. The most direct, once and for all, the safest way to find the warning code directly, instead of warning. This is the safest way.

But 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 sources that are not written by us, they may be updated at any time. Our approach is obviously not desirable.

two。 Use the macros provided by the compiler to operate, which will be seen a lot in our project:

# pragma clang diagnostic push#pragma clang diagnostic ignored "- Wdeprecated-declarations" / / any code written in the middle will not be prompted by the compiler-warning of type Wdeprecated-declarations dispatch_queue_tcurrentQueue = dispatch_get_current_queue (); # pragma clang diagnostic pop

The problem in this way is similar to the first one, and it is also necessary to modify the implementation of the source code. for third parties, we certainly do not want to change it, especially for some third parties who update frequently. The author updated shortly after the general warning appeared, and it would be wasteful for us to do so here. And when adding arm64 support, there are hundreds of warnings of some kind, which is quite time-consuming and laborious to change!

For example, our project opens arm64 and compiles:

3. Turn off a warning of a specified type for a specified file

Here, take a specific project. For example, there is a file PresencePacket in our project.

In fact, it is very simple to turn off a certain type of warning for a specified file, just as we used to add a certain type of warning to a file when we added ARC support or not.

Double-click the file and add-Wno-shorten-64-to-32 to it (the key is to make the compiler ignore the Implicit conversion loses integer precision: 'NSInteger' (aka' long') to 'int32_t' (aka' int') warning)

After adding and compiling, then the Implicit conversion loses integer precision: 'NSInteger' (aka' long') to 'int32_t' (aka' int') warning in the PresencePacket file is gone, isn't it very simple and convenient.

In this way, the workload has been greatly reduced, just add-Wno-shorten-64-to-32 to the compilation of the specified file. Is there any way for the compiler to ignore warnings of the specified type throughout the project?

4. Turn off 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 to it

Then recompile, , the Implicit conversion loses integer precision: 'NSInteger' (aka' long') to 'int32_t' (aka' int') warnings in the whole file have all disappeared!

5. You may be wondering, where did the above-Wno-shorten-64-to-32 come from? how do I know that Implicit conversion loses integer precision: 'NSInteger' (aka' long') to 'int32_t' (aka' int') warning is-Wno-shorten-64-to-32 type? Here, there is no need to remember, when there is this type of warning in the project.

In the warning window, on a warning, we right-click, display the right-click menu, and select Reveal in Log

Will be displayed

Notice that [- Wshorten-64-to-32], in this parenthesis is the type of warning-W is the prefix, and this prefix indicates turning on this type of warning. If we are going to turn off some type of warning, replace-W with-Wno-.

So you get-Wno-shorten-64-to-32.

This is the end of this article on "how to remove some type of warning from the Xcode project". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report