Summary of "e-commerce projects" (1) nslog usage skills

Source: Internet
Author: User
Premise: When xcode is used for development and debugging, it is often necessary to print some debugging information for debugging. As you know, when there are too many information to print, it may not be a problem to run on the simulator, because the simulator uses computer hardware, but when the application runs on the device, these output statements will greatly affect the application performance, to solve this problem, you can write some macros to control the output of the debugging information. The nslog content cannot be output in the release version:

Because nslog output consumes system resources, and the output data may expose the confidential data in the app, you must block all the output when releasing the official version.

We can comment out all nslog statements before releasing the version, and cancel the comments before debugging. This is really boring and time-consuming! Fortunately, there is a more elegant solution, that is, the prefix in the project. add the following code to the PCH file. After the code is added, nslog is output only under debug, but not under release.

How to implement: In-prefix. PCH (PCH stands for "precompiled header", that is, the pre-compiled header file. Some codes that are not frequently modified in the project stored in this file, such as common framework header files, this aims to increase the compilation speed of the compiler. We know that when we modify the code of a file in a project, the compiler does not recompile all the files, but compiles and modifies the files. If a file in PCH is modified, in this case, other files contained in the entire PCH file will be re-compiled, which will consume a lot of time, therefore, it is best to add files that are rarely changed or do not change the header file or pre-compiled code snippets;) add files
#ifdef DEBUG#define NSLog(...) NSLog(__VA_ARGS__)#define debugMethod() NSLog(@"%s", __func__)#else#define NSLog(...)#define debugMethod()#endif

The code in the previous section refers to the macro command to make a judgment. If debug is true, the # ifdef to # endif macro definition will be compiled; otherwise, the compiler will not compile the Code;

 

Where can I set this debug,

There is a "DEBUG = 1" in "target> build Settings> Preprocessor macros> debug ".

In debug mode, nslog can be printed when product --> scheme --> schemeedit scheme is set to build configuration to debug. Set release and the app version will not be printed when released, improving performance.
Related Article

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.