Use of PCH files

Source: Internet
Author: User

Application Scenarios for PCH files:
1. Used to define some global macros
2. Used to import some global access to the header file (if only need to let. m or. mm file access, do not need to let. c file access, then you need to write the head file to #ifdef _objc_ #endif之间, because. m and. mm files have a default _objc_ Macros and. c files are not ).
3. Use the log from definition
The contents of the PCH file can be accessed by all files, including. C,. m,. mm files. The default. m,. mm files have a # define _OBJC_ macro, and. c files do not have the macro, so you can take the. m,. mm access to the. h header file that you need to access without the. c file into this macro of the PCH file, and put the. c file into this macro of the PCH file that needs to be accessed.

1. ——————————————————
#define _global_

2. ——————————————————
#ifdef _OBJC_

#import "Ws.h"

#endif


3. ——————————————————
For debugging convenience, the debug phase often uses NSLog () to print out the output information to see if the information program is running correctly
However, the release phase often does not need to output these debugging information, manual comment or delete nslog () will be more troublesome, so you can use the following methods to operate:
In the PCH file,
#ifdef _OBJC_
#endif
Added between
#define WSLOG (...) NSLog (__va_args__)

// Commissioning Phase: #ifdef _objc_ #define Wslog (...) NSLog (__va_args__)#endif//  release phase:#ifdef  _objc_#define // NSLog (__va_args__) #endif


Or a smarter notation:

#ifdef _objc_ #ifdef Debug  /  debug Phase #define wslog (...) NSLog (__va_args__)#else              //  release phase #define wslog (...) #endif #endif

The relative path of the PCH needs to be set in the project:

Click Project->building setting-> Search prefix header-> Enter the relative path of the PCH file in the project, such as:

Note: The absolute path is not set:/users/user name/desktop/wechat/wechat/prefixheader.pch

The path to the correct PCH file that needs to be set: wechat/prefixheader.pch

Use of PCH files

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.