The use of #pragma in iOS

Source: Internet
Author: User
In the development process, we can add the following code before the method to provide a similar method annotation function, which provides annotations and also facilitates a quick positioning of your own method in the navigation bar above the code area.
#pragma mark-message
Then in the code process if there are some warnings to ignore (note not fatal error!) You can join at the top of the file
#pragma clang diagnostic ignored "-W warning name"

For example, a variable system that has not been used in the code prompts unused variable ' variable ', which allows you to use '-wunused ' or '-wunused-variable ' to ignore the warning!

I do not know how the version of the adaptation is done, I was in the judgement of the version number for different versions of different processing, but some past versions of some methods have been disabled,

At this point, some of the little neat people can join.

#pragma clang diagnostic ignored "-wdeprecated"
But some of the methods that you don't know but have expired will be blocked, so you can use the Segmented shield warning
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-wdeprecated"
    [nsurlconnection Connectionwithrequest:request delegate:self];
#pragma clang diagnostic pop
Open at push, end at pop, ignore alarm when ignored starts

For the warning, in fact, we usually practice in the project to use the warning is only a small part of the project in the building setting search warning,

We can see that there are a lot of warning switches for language types and even all languages under Apple LLVM, so let's get to know each other!

If we pursue the rigor and caution of the code we can add some warnings that we don't normally use.

Here we can add-wall,-wextra,-weverything to the other C Flags, which is not recommended in the debugging process! It's easy to get a mental breakdown!

What needs to be explained here is that-wall is not all warnings, but contains most of the warning if you want to turn on all warnings-weverything!

There are a lot of warnings that the compiler developer uses, but it also makes our code clearer and more standard! The recommended code release phase is best to turn on other warnings!

Finally, we can add to the project

#warning this is a warning
To add a warning to remind us that there are some places to pay attention to!

We can even add some

#error this is a error
To add a serious warning to remind us that there are other things that we did not do, such as the need to add other libraries when writing a third-party library,

We can manually add a serious warning, which is much more eye-catching than adding a note to the note!




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.