Use of IOS NSLog and the use of PCH

Source: Internet
Author: User

iOS Development note (one) iOS development NSLog use tips in xcode6.01 before there are prefix.pch files, Xcode6.01 will not have, but can create their own! Prerequisites:in Xcode to do development debugging often need to print some debugging information to do debug, we know that when the printing of information more places in the simulator run may not have any problems, Because the simulator uses the hardware of the computer but when the application runs on the device, these output statements will affect the performance of the application to a large extent, and for this problem, some macros can be written to control the output of these debugging information.


Disable output of NSLog content in release version

Because the output of the nslog is more expensive than the system resources, and the output data may also expose the confidential data in the app, so the release of the official version of the need to screen out all of the output.

It is a dull and time-consuming thing to comment out all the nslog statements before we release the version, and then cancel the comments when we want to debug them later. Fortunately, there is a more elegant solution, is to add the following piece of code in the project's prefix.pch file, after joining, NSLog only in the debug output, release under not output.


How to achieve: in-prefix.pch (PCH full name is "precompiled Header", that is, the precompiled header file, which is stored in the project some infrequently modified code, such as the usual framework header file, so that the purpose of improving the compiler speed. We know that when we modify a file code in a project, the compiler does not recompile all the files, but compiles the changed files, if a file in the PCH is modified, then the other files contained in the PCH file will be recompiled once, which will consume a lot of time. So it is better to add the file inside the header file that is rarely changed or not changed or is precompiled Code snippet;) file to add [Plain]View Plaincopy
  1. #ifdef DEBUG
  2. #define NSLOG (...) NSLog (__va_args__)
  3. #define DEBUGMETHOD () NSLog (@ "%s", __func__)
  4. #else
  5. #define NSLOG (...)
  6. #define DEBUGMETHOD ()
  7. #endif

The above code means to make a judgment with the macro command, if the debug is true, then compile #ifdef to #endif macro definition, otherwise the compiler will not compile;



Where does this debug set up,

There is a "debug=1" in "Target > Build Settings > Preprocessor Macros > Debug".

set to debug mode, Product-->scheme-->schemeedit scheme
when you set the build configuration to debug, you can print the NSLog.
set up release, which will not print when the app version is published, improves performance

Use of IOS NSLog and the use of PCH

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.