Open-source Chinese IOS client learning-(1) prefix. PCH File

Source: Internet
Author: User
Tags html header

When we create a new project, we will see a prefix in the supporting files file. the file ending with PCH. PCH is the "precompiled header", that is, the pre-compiled header file. Some codes that are not frequently modified in the project stored in the 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 a few or no changes to the header file or pre-compiled code snippets;


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

#import <Availability.h>#ifndef __IPHONE_4_0#warning "This project uses features only available in iOS SDK 4.0 and later."#endif#ifdef __OBJC__    #import <UIKit/UIKit.h>    #import <Foundation/Foundation.h>#endif

You may think that this pre-compiled code is rare, but you can check the definition file in uikit. h.

////  UIKit.h//  UIKit////  Copyright (c) 2005-2011, Apple Inc. All rights reserved.//#import <UIKit/UIKitDefines.h>#import <UIKit/UIAccelerometer.h>#import <UIKit/UIAccessibility.h> #import <UIKit/UIActivityIndicatorView.h>#import <UIKit/UIAlert.h>#import <UIKit/UIApplication.h>#import <UIKit/UIBarButtonItem.h>#import <UIKit/UIBarItem.h>#import <UIKit/UIBezierPath.h>#import <UIKit/UIButton.h>#import <UIKit/UIColor.h>#import <UIKit/UIControl.h>#import <UIKit/UIDataDetectors.h>#import <UIKit/UIDatePicker.h>#import <UIKit/UIDevice.h>#import <UIKit/UIDocument.h>#import <UIKit/UIDocumentInteractionController.h>#import <UIKit/UIEvent.h>#import <UIKit/UIFont.h>#import <UIKit/UIGeometry.h>#import <UIKit/UIGestureRecognizer.h>#import <UIKit/UIGraphics.h>#import <UIKit/UIImage.h>#import <UIKit/UIImagePickerController.h>#import <UIKit/UIImageView.h>#import <UIKit/UIInterface.h>#import <UIKit/UILabel.h>#import <UIKit/UILocalNotification.h>#import <UIKit/UILocalizedIndexedCollation.h>#import <UIKit/UILongPressGestureRecognizer.h>#import <UIKit/UIManagedDocument.h>#import <UIKit/UIMenuController.h>#import <UIKit/UINavigationBar.h>#import <UIKit/UINavigationController.h>#import <UIKit/UINib.h>#import <UIKit/UINibDeclarations.h>#import <UIKit/UINibLoading.h>#import <UIKit/UIPageControl.h>#import <UIKit/UIPageViewController.h>#import <UIKit/UIPanGestureRecognizer.h>#import <UIKit/UIPasteboard.h>#import <UIKit/UIPickerView.h>#import <UIKit/UIPinchGestureRecognizer.h>#import <UIKit/UIPopoverController.h>#import <UIKit/UIPopoverBackgroundView.h>#import <UIKit/UIPrintError.h>#import <UIKit/UIPrintFormatter.h>#import <UIKit/UIPrintInfo.h>#import <UIKit/UIPrintInteractionController.h>#import <UIKit/UIPrintPageRenderer.h>#import <UIKit/UIPrintPaper.h>#import <UIKit/UIProgressView.h>#import <UIKit/UIReferenceLibraryViewController.h>#import <UIKit/UIResponder.h>#import <UIKit/UIRotationGestureRecognizer.h>#import <UIKit/UIScreen.h>#import <UIKit/UIScreenMode.h>#import <UIKit/UIScrollView.h>#import <UIKit/UISearchBar.h>#import <UIKit/UISearchDisplayController.h>#import <UIKit/UISegmentedControl.h>#import <UIKit/UISlider.h>#import <UIKit/UISplitViewController.h>#import <UIKit/UIStepper.h>#import <UIKit/UIStoryboard.h>#import <UIKit/UIStoryboardPopoverSegue.h>#import <UIKit/UIStoryboardSegue.h>#import <UIKit/UIStringDrawing.h>#import <UIKit/UISwipeGestureRecognizer.h>#import <UIKit/UISwitch.h>#import <UIKit/UITabBar.h>#import <UIKit/UITabBarController.h>#import <UIKit/UITabBarItem.h>#import <UIKit/UITableView.h>#import <UIKit/UITableViewCell.h>#import <UIKit/UITableViewController.h>#import <UIKit/UITapGestureRecognizer.h>#import <UIKit/UITextField.h>#import <UIKit/UITextInput.h>#import <UIKit/UITextInputTraits.h>#import <UIKit/UITextView.h>#import <UIKit/UIToolbar.h>#import <UIKit/UITouch.h>#import <UIKit/UIVideoEditorController.h>#import <UIKit/UIView.h>#import <UIKit/UIViewController.h>#import <UIKit/UIWebView.h>#import <UIKit/UIWindow.h>


It takes a lot of time to compile the project every time. These are the standard headers defined by Apple. We cannot or have the permission to modify these header file definitions, when placed in the PCH file, the compilation process will be accelerated;


Let's take a look at our open-source Chinese IOS client PCH file.

/// Prefix header for all source files of the 'ossina' target in the 'ossina' project // # import <availability. h> # ifndef _ iphone_4_0 # warning "This project uses features only available in ios sdk 4.0 and later. "# endif # ifdef _ objc _ # import <uikit/uikit. h> # import <Foundation/Foundation. h> # import <coredata/coredata. h> # import <quartzcore/quartzcore. h> // pre-compiled # import "asihttprequest. H "# import" asiformdatarequest. H "# import" asihttprequestdelegate. H "# import" asihttprequestconfig. H "# import" tbxml. H "# import" tbxml + HTTP. H "# import" tbxml + compression. H "# import" config. H "# import" egorefreshtableheaderview. H "# import" datasingleton. H "# import" imgrecord. H "# import" icondownloader. H "# import" mbprogresshud. H "# import" gcdiscreetnotificationview. H "# import" nduncaughtexceptionhandler. H "# import" jsnotifier. H "# import" afoscclient. H "# import" afhttprequestoperation. H "# import" afxmlrequestoperation. H "// API definition # define api_news_list @" http://www.oschina.net/action/api/news_list "# define api_news_detail @" http://www.oschina.net/action/api/news_detail "# define api_post_list @" http://www.oschina.net/action/api/post_list "# define api_post_detail @" http://www.oschina.net/action/api/post_detail "# define buy @" http://www.oschina.net/action/api/post_pub "# define api_tweet_list @" http://www.oschina.net/action/api/tweet_list "# define items @" http://www.oschina.net/action/api/tweet_detail "# define api_tweet_delete @" http://www.oschina.net/action/api/tweet_delete "# define items @" http://www.oschina.net/action/api/tweet_pub "# define api_active_list @" http://www.oschina.net/action/api/active_list "# define api_message_list @ "http://www.oschina.net/action/api/message_list" # define api_message_delete @ "http://www.oschina.net/action/api/message_delete" # define items @ "http://www.oschina.net/action/api/message_pub" # define api_comment_list @ "http://www.oschina.net/action/api/comment_list" # define items @ "http://www.oschina.net/action/api/comment_pub" # define api_comment_reply @ "http://www.oschina.net/action/api/comment_reply" # define api_comment_delete @ "http://www.oschina.net/action/api/comment_delete" # define items @ "https://www.oschina.net/action/api/login_validate" # define api_user_info @ "http://www.oschina.net/action/api/user_info" # define api_user_information @ "http://www.oschina.net/action/api/user_information" # define items @ "http://www.oschina.net/action/api/user_updaterelation" # define api_notice_clear @ "http://www.oschina.net/action/api/notice_clear" # define api_software_detail @ "http://www.oschina.net/action/api/software_detail" # define api_blog_detail @ "http://www.oschina.net/action/api/blog_detail" # define detail @ "http://www.oschina.net/action/api/favorite_list" # define detail @ "http://www.oschina.net/action/api/favorite_add" # define detail @ "http://www.oschina.net/action/api/favorite_delete" # define api_user_notice @" http://www.oschina.net/action/api/user_notice "# define api_search_list @" http://www.oschina.net/action/api/search_list "# define api_friends_list @" http://www.oschina.net/action/api/friends_list "# define items @" http://www.oschina.net/action/api/softwarecatalog_list "# define api_software_list @" http://www.oschina.net/action/api/software_list "# define items @" http://www.oschina.net/action/api/softwaretag_list "# define items @ "http://www.oschina.net/action/api/blogcomment_list" # Define Login @ "http://www.oschina.net/action/api/blogcomment_pub" # define api_my_information @ "http://www.oschina.net/action/api/my_information" # Define Login @ "http://www.oschina.net/action/api/blogcomment_delete" # define api_userblog_delete @ "http://www.oschina.net/action/api/userblog_delete" # define api_userblog_list @ "http://www.oschina.net/action/api/userblog_list "# define identifier @ "http://www.oschina.net/action/api/blog_list" # define api_userinfo_update @ "http://www.oschina.net/action/api/portrait_update" // macro definition news # define identifier @ "identifier" # define loadmoreidentifier @ "loadmoreidentifier" # define newscellidentifier @ "identifier" # define postcellidentifier @ "postcellidentifier" # define guest @ "Taobao" # define guest @ "Taobao" # define activecellidentifier @ "activecellidentifier" # define guest @ "Taobao" # define guest @ "Taobao" # define rtactivecellidentifier @ "rtactivecellidentifier" # define guest @ "guest" # define profielcellidentifier @ "guest" # define guest @" pipeline "# define pipeline @" Pipeline "# define pipeline @" softwarecellidentifier "# define pipeline @" Pipeline "# define settingtableidentifier @" settingtableidentifier "# define pipeline @" Pipeline "# define Pipeline @ "myportraitcellidentifier" # define loadnext20tip @ "the following 20 items... "# define loadingtip @" loading... "# define networkerror @" No network connection "# define nonetworktip @" No network connection "// fixed Message notification string # define notif_noticeupdate @" icationication_noticeupdate "# define notification_noticeupdate "# define notification_tabclick @ "notification_tabclick" // html header # 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; padding: 5px ;}</style> "# define html_bottom @" <Div style = 'margin-bottom: 60px '/> "# define useragent @" oschina. net/IOS/5.0 "# define appversion @" 1.6.1 "# ifdef debug # define debuglog (...) nslog (_ va_args _) # define debugmethod () nslog (@ "% s", _ FUNC _) # else # define debuglog (...) # define debugmethod () # endif

We can see that some of these files are also added to the file. May you wonder if these header files have not changed much?

// Added pre-compilation # import "asihttprequest. H "# import" asiformdatarequest. H "# import" asihttprequestdelegate. H "# import" asihttprequestconfig. H "# import" tbxml. H "# import" tbxml + HTTP. H "# import" tbxml + compression. H "# import" config. H "# import" egorefreshtableheaderview. H "# import" datasingleton. H "# import" imgrecord. H "# import" icondownloader. H "# import" mbprogresshud. H "# import" gcdiscreetnotificationview. H "# import" nduncaughtexceptionhandler. H "# import" jsnotifier. H "# import" afoscclient. H "# import" afhttprequestoperation. H "# import" afxmlrequestoperation. h"

In fact, these files are all header files of the third-party class library. The third-party class library encapsulates some objects and leaves interfaces. Then we can directly call these files based on the class library interface, these third-party libraries are generally easier to use than the native libraries of iOS, such as the tbxml parser library, which is better than the nsxmlpaser parser of IOS;


Some macro definitions are commonly used macro definitions, such as the open-source API interfaces of the Chinese community, which of course become rare;


Then the last one is left.

#ifdef DEBUG#define debugLog(...) NSLog(__VA_ARGS__)#define debugMethod() NSLog(@"%s", __func__)#else#define debugLog(...)#define debugMethod()#endif

The project includes debug version and release version. debug version is the version during program development. It contains all debugging information and some common nslog printing logs, during the program debugging process, the engineer can see what went wrong according to the debugging information we set. Will we first consider breakpoint debugging when running a small program, you should first think about nslog to see which function method is not executed and whether the value of the array is not obtained. Release
Version is the release version. If nslog is not printed, the program running speed can be accelerated and the memory usage can be reduced. However, there will be a lot of such nslogs in a major project. When our project runs perfectly and the release version is released, do we need to annotate and tune the nslog line? If a version 1.2 version is released on the basis of the project, it will be very troublesome if we don't cancel the original comments when modifying the program.

Therefore, macro commands are used here.


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


Now let's do a test:

Place a macro command in the application: didfinishlaunchingwitexceptions: Method of osappdelegate. M and compare it with the same nslog;

Nslog (@ "% s", _ FUNC __);

Debugmethod ();

First, set it to "product --> edit Scheme" in debug mode.

Go to this page


When I set build configuration to debug, print


When I set build configuration to release, print

When running test profile analyze archive, you can set both Debug and release modes as needed;

Therefore, we can use a macro command to set whether to print debugging information;




Welcome to share, please indicate the source of http://blog.csdn.net/duxinfeng2010

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.