The PCH file and NSLog real machine are not printed during iOS development.

Source: Internet
Author: User

The PCH file and NSLog real machine are not printed during iOS development.
Add a PCH File

Now, when creating a new project in Xcode6 and 7, the PCH file is no longer included by default. You need to manually add the PCH file.

Under the Supporting Files directory, select File> New> File> iOS> Other> PCH File and click Next to name the File. The recommended naming format is project name-Prefix and Demo.
Connect the created PCH file to the compiler Xcode: Find the Project> Build Settings> search for "Prefix Header", and find the Prefix Header in the Apple LLVM X.0-Language column, double-click and add the PCH file address ,:

In this way, the PCH files of Xcode6 and 7 can be smoothly added to the project. NSLog function real machine does not print

In actual projects, printing NSLog function information is essential and can help us Debug programs in a friendly manner. However, the simulator occupies the computer's memory, however, if the NSLog function is not blocked when a real machine goes online, it will inevitably cause memory usage and performance degradation. This is very contrary to the starting point of making an excellent App, therefore, in a real machine, setting global variables without printing NSLog functions with PCH is an essential requirement in actual projects.

The NSLog was transformed in the PCH just created:

# Ifdef DEBUG # define DLog (fmt ,...) NSLog (@ "[File Name: % s] \ n" "[function name: % s] \ n" "[row number: % d] \ n" fmt ), _ FILE __, _ FUNCTION __, _ LINE __, ##__va_args _); # define DeBugLog (fmt ,...) NSLog (@ "% s [Line % d]" fmt), _ PRETTY_FUNCTION __, _ LINE __, ##__ VA_ARGS __); # define NSLog (...) NSLog (_ VA_ARGS _); # define MyNSLog (FORMAT ,...) fprintf (stderr, "[% s]: [line % d] % s \ n", [[NSString stringwithuf8string :__ FILE _] lastPathComponent] UTF8String], _ LINE __, [[NSString stringWithFormat: FORMAT, ##__va_args _] UTF8String]); # else # define DLog (...) # define DeBugLog (...) # define NSLog (...) # define MyNSLog (FORMAT ,...) nil # endif

 
* 1) VA_ARGS is a variable parameter macro, which is rarely known. The macro of this variable parameter is added in the new C99 specification, currently, only gcc is supported (not supported by the VC6.0 compiler ). # Is added before the Macro. When the number of variable parameters is 0, # is used to remove ",". Otherwise, compilation errors may occur, you can try.

2) The FILE Macro will be replaced with the current source FILE name during pre-compilation.

3) The LINE Macro will be replaced with the current row number during pre-compilation.

4) The FUNCTION macro will be replaced with the current FUNCTION name during pre-compilation.

OK. Test it! Mutual switching between real machines and Simulation


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.