iOS development--pch file add and use

Source: Internet
Author: User

Add PCH File

After Xcode6 does not automatically create-prefix.pch files to your project, so we want to use the PCH file, we have to manually import, the following describes how to manually add the PCH file to the project directory.
(1) Open the Xcode project that you already exist. Select File > New > File > IOS > Other > PCH File and click Next.

(2) Give your PCH file a name projectname-prefix.pch. For example, your project is named Smalldemo however your PCH file name should be smalldemo-prefix.pch and then click the Create button.

(3) Find Project > Build Settings > Search "Prefix Header"

(4) Locate the Apple LLVM X.0-language as shown in the figure, and then locate the prefix Header, and then double-click to add the PCH file address.

The PCH file is then added to the project directory.

PCH file use--nslog function True machine does not print

In the actual project NSLog function printing information is essential thing, can be friendly to help us debug the program, but in the simulator is occupied by the computer's memory, but in the real machine on the line if the NSLog function is not shielded, will inevitably result in memory consumption, performance weakening, This is a good app for the starting point is very inconsistent, so in the real machine with PCH set global variables do not print NSLog function is an essential requirement in the actual combat project.

The implementation method is as follows:
Select the PCH file (the example file for the article is smalldemo-prefix.pch) and replace the contents of the file as follows.

#ifdef DEBUG  #define DLOG (FMT, ...) NSLog (@ "[File name:%s]\n" "[function name:%s]\n] "[line 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__);%s\n", [[[NSString stringwithutf8string:__file__] lastpathcomponent] utf8string],__LINE__, [[NSString Stringwithformat:format,# #__VA_ARGS__] Utf8string]);  #else  #define DLOG (...)  #define Debuglog (...)  #define NSLOG (...)  #define MYNSLOG (FORMAT, ...) nil  #endif

You can save this code and import it directly when you need it. With the real machine does not print, the obvious application smooth a lot.

iOS development--pch file add and use

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.