Use of the. pch file developed by iOS

Source: Internet
Author: User
Tags html header uikit

Case: Open source China iOS client When we create a new project, under the supporting files file will see a file ending with-prefix.pch, PCH full name is "precompiled Header", that is, the precompiled header file, the file stored in the project Some of the less frequently modified code, such as a commonly used framework header file, is intended to improve compiler compilation 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. Therefore it is better to add the file inside the header file that is rarely changed or not changed, or is a precompiled code fragment;


When you create a new project, the code in the PCH suffix file is

    1. #import <Availability.h>
    2. #ifndef __IPHONE_4_0
    3. #warning "This project uses features only available in IOS SDK 4.0 and later."
    4. #endif
    5. #ifdef __objc__
    6. #import <UIKit/UIKit.h>
    7. #import <Foundation/Foundation.h>
    8. #endif
Copy Code

You might think this precompiled code is rare, but you can look at the UIKit.h definition file


  1. //
  2. UIKit.h
  3. UIKit
  4. //
  5. Copyright (c) 2005-2011, Apple Inc. All rights reserved.
  6. //
  7. #import <UIKit/UIKitDefines.h>
  8. #import <UIKit/UIAccelerometer.h>
  9. #import <UIKit/UIAccessibility.h>
  10. #import <UIKit/UIActivityIndicatorView.h>
  11. #import <UIKit/UIAlert.h>
  12. #import <UIKit/UIApplication.h>
  13. #import <UIKit/UIBarButtonItem.h>
  14. #import <UIKit/UIBarItem.h>
  15. #import <UIKit/UIBezierPath.h>
  16. #import <UIKit/UIButton.h>
  17. #import <UIKit/UIColor.h>
  18. #import <UIKit/UIControl.h>
  19. #import <UIKit/UIDataDetectors.h>
  20. #import <UIKit/UIDatePicker.h>
  21. #import <UIKit/UIDevice.h>
  22. #import <UIKit/UIDocument.h>
  23. #import <UIKit/UIDocumentInteractionController.h>
  24. #import <UIKit/UIEvent.h>
  25. #import <UIKit/UIFont.h>
  26. #import <UIKit/UIGeometry.h>
  27. #import <UIKit/UIGestureRecognizer.h>
  28. #import <UIKit/UIGraphics.h>
  29. #import <UIKit/UIImage.h>
  30. #import <UIKit/UIImagePickerController.h>
  31. #import <UIKit/UIImageView.h>
  32. #import <UIKit/UIInterface.h>
  33. #import <UIKit/UILabel.h>
  34. #import <UIKit/UILocalNotification.h>
  35. #import <UIKit/UILocalizedIndexedCollation.h>
  36. #import <UIKit/UILongPressGestureRecognizer.h>
  37. #import <UIKit/UIManagedDocument.h>
  38. #import <UIKit/UIMenuController.h>
  39. #import <UIKit/UINavigationBar.h>
  40. #import <UIKit/UINavigationController.h>
  41. #import <UIKit/UINib.h>
  42. #import <UIKit/UINibDeclarations.h>
  43. #import <UIKit/UINibLoading.h>
  44. #import <UIKit/UIPageControl.h>
  45. #import <UIKit/UIPageViewController.h>
  46. #import <UIKit/UIPanGestureRecognizer.h>
  47. #import <UIKit/UIPasteboard.h>
  48. #import <UIKit/UIPickerView.h>
  49. #import <UIKit/UIPinchGestureRecognizer.h>
  50. #import <UIKit/UIPopoverController.h>
  51. #import <UIKit/UIPopoverBackgroundView.h>
  52. #import <UIKit/UIPrintError.h>
  53. #import <UIKit/UIPrintFormatter.h>
  54. #import <UIKit/UIPrintInfo.h>
  55. #import <UIKit/UIPrintInteractionController.h>
  56. #import <UIKit/UIPrintPageRenderer.h>
  57. #import <UIKit/UIPrintPaper.h>
  58. #import <UIKit/UIProgressView.h>
  59. #import <UIKit/UIReferenceLibraryViewController.h>
  60. #import <UIKit/UIResponder.h>
  61. #import <UIKit/UIRotationGestureRecognizer.h>
  62. #import <UIKit/UIScreen.h>
  63. #import <UIKit/UIScreenMode.h>
  64. #import <UIKit/UIScrollView.h>
  65. #import <UIKit/UISearchBar.h>
  66. #import <UIKit/UISearchDisplayController.h>
  67. #import <UIKit/UISegmentedControl.h>
  68. #import <UIKit/UISlider.h>
  69. #import <UIKit/UISplitViewController.h>
  70. #import <UIKit/UIStepper.h>
  71. #import <UIKit/UIStoryboard.h>
  72. #import <UIKit/UIStoryboardPopoverSegue.h>
  73. #import <UIKit/UIStoryboardSegue.h>
  74. #import <UIKit/UIStringDrawing.h>
  75. #import <UIKit/UISwipeGestureRecognizer.h>
  76. #import <UIKit/UISwitch.h>
  77. #import <UIKit/UITabBar.h>
  78. #import <UIKit/UITabBarController.h>
  79. #import <UIKit/UITabBarItem.h>
  80. #import <UIKit/UITableView.h>
  81. #import <UIKit/UITableViewCell.h>
  82. #import <UIKit/UITableViewController.h>
  83. #import <UIKit/UITapGestureRecognizer.h>
  84. #import <UIKit/UITextField.h>
  85. #import <UIKit/UITextInput.h>
  86. #import <UIKit/UITextInputTraits.h>
  87. #import <UIKit/UITextView.h>
  88. #import <UIKit/UIToolbar.h>
  89. #import <UIKit/UITouch.h>
  90. #import <UIKit/UIVideoEditorController.h>
  91. #import <UIKit/UIView.h>
  92. #import <UIKit/UIViewController.h>
  93. #import <UIKit/UIWebView.h>
  94. #import <UIKit/UIWindow.h>
Copy Code

This is a lot of it, the project every time the compilation is not very time-consuming, these are Apple's internal definition of standard header files, we can not and do not have permission to modify these header file definition content, so, when placed in the PCH file will speed up the compilation process;



Take a look at our open source China iOS client PCH file

  1. //
  2. Prefix header for all source files of the ' Oschina ' target in the ' Oschina ' project
  3. //
  4. #import <Availability.h>
  5. #ifndef __IPHONE_4_0
  6. #warning "This project uses features only available in IOS SDK 4.0 and later."
  7. #endif
  8. #ifdef __objc__
  9. #import <UIKit/UIKit.h>
  10. #import <Foundation/Foundation.h>
  11. #import <CoreData/CoreData.h>
  12. #import <QuartzCore/QuartzCore.h>
  13. Pre-compilation added
  14. #import "ASIHTTPRequest.h"
  15. #import "ASIFormDataRequest.h"
  16. #import "ASIHTTPRequestDelegate.h"
  17. #import "ASIHTTPRequestConfig.h"
  18. #import "TBXML.h"
  19. #import "Tbxml+http.h"
  20. #import "Tbxml+compression.h"
  21. #import "Config.h"
  22. #import "EGORefreshTableHeaderView.h"
  23. #import "DataSingleton.h"
  24. #import "ImgRecord.h"
  25. #import "IconDownloader.h"
  26. #import "MBProgressHUD.h"
  27. #import "GCDiscreetNotificationView.h"
  28. #import "NdUncaughtExceptionHandler.h"
  29. #import "JSNotifier.h"
  30. #import "AFOSCClient.h"
  31. #import "AFHTTPRequestOperation.h"
  32. #import "AFXMLRequestOperation.h"
  33. API definition
  34. #define Api_news_list @ "Http://www.oschina.net/action/api/news_list"
  35. #define Api_news_detail @ "Http://www.oschina.net/action/api/news_detail"
  36. #define Api_post_list @ "Http://www.oschina.net/action/api/post_list"
  37. #define Api_post_detail @ "Http://www.oschina.net/action/api/post_detail"
  38. #define API_POST_PUB @ "Http://www.oschina.net/action/api/post_pub"
  39. #define Api_tweet_list @ "Http://www.oschina.net/action/api/tweet_list"
  40. #define Api_tweet_detail @ "Http://www.oschina.net/action/api/tweet_detail"
  41. #define API_TWEET_DELETE @ "Http://www.oschina.net/action/api/tweet_delete"
  42. #define API_TWEET_PUB @ "Http://www.oschina.net/action/api/tweet_pub"
  43. #define Api_active_list @ "Http://www.oschina.net/action/api/active_list"
  44. #define Api_message_list @ "Http://www.oschina.net/action/api/message_list"
  45. #define API_MESSAGE_DELETE @ "Http://www.oschina.net/action/api/message_delete"
  46. #define API_MESSAGE_PUB @ "Http://www.oschina.net/action/api/message_pub"
  47. #define Api_comment_list @ "Http://www.oschina.net/action/api/comment_list"
  48. #define API_COMMENT_PUB @ "Http://www.oschina.net/action/api/comment_pub"
  49. #define API_COMMENT_REPLY @ "Http://www.oschina.net/action/api/comment_reply"
  50. #define API_COMMENT_DELETE @ "Http://www.oschina.net/action/api/comment_delete"
  51. #define Api_login_validate @ "Https://www.oschina.net/action/api/login_validate"
  52. #define API_USER_INFO @ "Http://www.oschina.net/action/api/user_info"
  53. #define Api_user_information @ "Http://www.oschina.net/action/api/user_information"
  54. #define Api_user_updaterelation @ "Http://www.oschina.net/action/api/user_updaterelation"
  55. #define Api_notice_clear @ "Http://www.oschina.net/action/api/notice_clear"
  56. #define Api_software_detail @ "Http://www.oschina.net/action/api/software_detail"
  57. #define Api_blog_detail @ "Http://www.oschina.net/action/api/blog_detail"
  58. #define Api_favorite_list @ "Http://www.oschina.net/action/api/favorite_list"
  59. #define API_FAVORITE_ADD @ "Http://www.oschina.net/action/api/favorite_add"
  60. #define API_FAVORITE_DELETE @ "Http://www.oschina.net/action/api/favorite_delete"
  61. #define Api_user_notice @ "Http://www.oschina.net/action/api/user_notice"
  62. #define Api_search_list @ "Http://www.oschina.net/action/api/search_list"
  63. #define Api_friends_list @ "Http://www.oschina.net/action/api/friends_list"
  64. #define Api_softwarecatalog_list @ "Http://www.oschina.net/action/api/softwarecatalog_list"
  65. #define Api_software_list @ "Http://www.oschina.net/action/api/software_list"
  66. #define Api_softwaretag_list @ "Http://www.oschina.net/action/api/softwaretag_list"
  67. #define Api_blogcomment_list @ "Http://www.oschina.net/action/api/blogcomment_list"
  68. #define API_BLOGCOMMENT_PUB @ "Http://www.oschina.net/action/api/blogcomment_pub"
  69. #define Api_my_information @ "Http://www.oschina.net/action/api/my_information"
  70. #define API_BLOGCOMMENT_DELETE @ "Http://www.oschina.net/action/api/blogcomment_delete"
  71. #define API_USERBLOG_DELETE @ "Http://www.oschina.net/action/api/userblog_delete"
  72. #define Api_userblog_list @ "Http://www.oschina.net/action/api/userblog_list"
  73. #define Api_blog_list @ "Http://www.oschina.net/action/api/blog_list"
  74. #define Api_userinfo_update @ "Http://www.oschina.net/action/api/portrait_update"
  75. Macro Definition News
  76. #define Tweetcellidentifier @ "Tweetcellidentifier"
  77. #define Loadmoreidentifier @ "Loadmoreidentifier"
  78. #define Newscellidentifier @ "Newscellidentifier"
  79. #define Postcellidentifier @ "Postcellidentifier"
  80. #define Msgcellidentifier @ "Msgcellidentifier"
  81. #define Msgunitcellidentifier @ "Msgunitcellidentifier"
  82. #define Activecellidentifier @ "Activecellidentifier"
  83. #define Useractivecellidentifier @ "Useractivecellidentifier"
  84. #define Coloractivecellidentifier @ "Coloractivecellidentifier"
  85. #define Rtactivecellidentifier @ "Rtactivecellidentifier"
  86. #define Coloruseractivecellidentifier @ "Coloruseractivecellidentifier"
  87. #define Profielcellidentifier @ "Profielcellidentifier"
  88. #define Commentcellidentifier @ "Commentcellidentifier"
  89. #define Normalcellidentifier @ "Normalcellidentifier"
  90. #define Favoritecellidentifier @ "Favoritecellidentifier"
  91. #define Friendcellidentifier @ "Friendcellidentifier"
  92. #define Softwarecellidentifier @ "Softwarecellidentifier"
  93. #define Softwarecatalogidentifier @ "Softwarecatalogidentifier"
  94. #define Settingtableidentifier @ "Settingtableidentifier"
  95. #define Myinfocellidentifier @ "Myinfocellidentifier"
  96. #define Myportraitcellidentifier @ "Myportraitcellidentifier"
  97. #define LOADNEXT20TIP @ "below 20 items ..."
  98. #define LOADINGTIP @ "Loading ..."
  99. #define NETWORKERROR @ "Network no Connection"
  100. #define NONETWORKTIP @ "Network no Connection"
  101. Message Notification fixed string
  102. #define NOTIFICATION_DETAILCOMMENTCOUNT @ "Notification_detailcommentcount"
  103. #define Notification_noticeupdate @ "Notification_noticeupdate"
  104. #define Notification_tabclick @ "Notification_tabclick"
  105. HTML header
  106. #define Html_style @ "<style> #oschina_title {color: #000000; margin-bottom:6px; font-weight:bold;} #oschina_title img{vertical-align:middle;margin-right:6px;} #oschina_title a{color: #0D6DA8;} #oschina_outline {color: #707070; font-size:12px;} #oschina_outline a{color: #0D6DA8;} #oschina_software {color: #808080; font-size:12px} #oschina_body img {max-width:300px;} #oschina_body {font-size:16px;max-width:300px;line-height:24px;} #oschina_body table{max-width:300px;} #oschina_body Pre {font-size:9pt;font-family:courier new,arial;border:1px solid #ddd; border-left:5px solid #6CE26C; Background: #f6f6f6;p adding:5px;} </style> "
  107. #define Html_bottom @ "<div style= ' margin-bottom:60px '/>"
  108. #define UserAgent @ "oschina.net/ios/5.0"
  109. #define AppVersion @ "1.6.1"
  110. #ifdef DEBUG
  111. #define DEBUGLOG (...) NSLog (__va_args__)
  112. #define DEBUGMETHOD () NSLog (@ "%s", __func__)
  113. #else
  114. #define DEBUGLOG (...)
  115. #define DEBUGMETHOD ()
  116. #endif
  117. #endif
Copy Code

We see that some of these files have also been added to the inside, and might wonder if these headers have changed much?

    1. Pre-compilation added
    2. #import "ASIHTTPRequest.h"
    3. #import "ASIFormDataRequest.h"
    4. #import "ASIHTTPRequestDelegate.h"
    5. #import "ASIHTTPRequestConfig.h"
    6. #import "TBXML.h"
    7. #import "Tbxml+http.h"
    8. #import "Tbxml+compression.h"
    9. #import "Config.h"
    10. #import "EGORefreshTableHeaderView.h"
    11. #import "DataSingleton.h"
    12. #import "ImgRecord.h"
    13. #import "IconDownloader.h"
    14. #import "MBProgressHUD.h"
    15. #import "GCDiscreetNotificationView.h"
    16. #import "NdUncaughtExceptionHandler.h"
    17. #import "JSNotifier.h"
    18. #import "AFOSCClient.h"
    19. #import "AFHTTPRequestOperation.h"
    20. #import "AFXMLRequestOperation.h"
Copy Code

In fact, these files are special in that they are the third-party class library header files, the third-party class library to highly encapsulate some objects, leaving the interface, and then we can directly call on the class library interface, these third-party libraries are generally more simple than the original native iOS, such as the Tbxml parsing library, It's better than the Nsxmlpaser parser speed function that comes with iOS.



There are also macro definitions that are more commonly used, such as the API interfaces of the defined open source Chinese community, which are, of course, rare;


And then the last thing left.

    1. #ifdef DEBUG
    2. #define DEBUGLOG (...) NSLog (__va_args__)
    3. #define DEBUGMETHOD () NSLog (@ "%s", __func__)
    4. #else
    5. #define DEBUGLOG (...)
    6. #define DEBUGMETHOD ()
    7. #endif
Copy Code

The project has debug version and release Version,debug versions is the program development process, it contains all the debugging information, some commonly used nslog print logs, in the program debugging process according to the debugging information we set can see what place error, We run a small program when running, will not be the first to think of debugging a breakpoint, it should be the first thought of NSLog, see which function method did not execute, to see if the value of which array is not taken out.   Release version is a release, and not printing nslog can speed up the program and reduce memory usage. But to a big project, there will be a lot of such nslog, when we work perfectly run, release release version of the time, we go to a line of comments NSLog? If the project is now based on the original version 1.2 release, we modify the program when the original comment is not also canceled, it is very troublesome and troublesome.

So, here's the macro directive.


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".



now let's do a test:
take a macro and put it in the OSAPPDELEGATE.M.Application:didfinishlaunchingwithoptions: In the method, make a contrast with the same nslog;


NSLog (@ "%s", __func__);

Debugmethod ();


first set to debug mode, Product-->edit scheme


Jump to this interface


When I set the build configuration to debug, the print


when I set the build configuration to release, when printing


when run Test Profile Analyze archive, the debug and release two modes can be set as required.
so we can use a macro command to set whether or not to print debugging information;

Use of the. pch file developed by iOS

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.