IOS to manually add compilation warnings yourself

Source: Internet
Author: User

The square of the paper/blue and white porcelain (Jane book author)
Original link: http://www.jianshu.com/p/b2e30cad2a0d
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

Reason

Last production environment we have a major bug, because ApplePay on-line, which has a macro file my colleague forgot to add version control, the test did not test (because it is a small version, ApplePay is not open), causing the online crash nearly million times, thanks to Jspatch, with the hot fix solved the problem. So the question is, how do you get developers to see the build warnings ahead of time so that they don't make such low-level mistakes?

Solve 1.xcodebuild

This is my first thought of the method, write shell script, in the form of automatic compilation detection. But there's a big problem with this:
(1) Xcode7 now supports the Simulator SDK is version 9.2, the other SDK needs to be downloaded from our own online, usually from the old version of Xcode, can be used Xcodebuild-showsdks to view the supported SDK, such as


201601181.png


Specific xcodebuild use of online a lot, I do not elaborate, Liu Wei's article is written in detail, can refer to: Xcodebuild command detailed.
(2) The second is to compile the other SDK for a long time (if it is a large project), write a script compilation is not much advantage.

2. Better ways to solve

A better solution is to have the compiler give a warning directly! So how do you get the compiler to give a warning?


201601182.png


The above image is referenced from Warn about new API Classes and Methods
How does the compiler give these warnings and error messages to the compiler for destroying methods in Xcode?
Specifically related to deprecated,unavailable these usages, refer to

[iossimulatorsdk] Usr/include/availability.h
[iossimulatorsdk] Usr/include/availabilityinternal.h

I found a very enlightening article on stack overflow: Is there a-to-XCode-warn about the new API calls?
Several of the answers were good, so we found the open source project Mjgavailability,
I modified this header file, added the API after iOS7, but eventually created a new project on Xcode7. Test discovery always has no compile warning, but there are warnings for properties and methods of custom labels, such as


201601184.png

At first, I thought it was uikit. System control is not placed in my custom header file, after a long time to feel that it should be in Xcode some of the compiler configuration problems, finally found to be enable Modules and Link Framwork Automatically reason, this is a technology after XCODE5, specific reference [IOS7 Objective-c and foundation of the new features], finally I set in debug mode enable Modules and Link The Framework automatically is no (a compile error may occur because the automatic connection is canceled and some associated library files need to be added manually)


201601185.png

Note: since we have redefined the system macros, this should not be done under release because doing so may cause some unpredictable problems, so you can add debug judgment to the PCH file

Demo

Specific demo on my GitHub testapilevel

IOS to manually add compilation warnings yourself

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.