profile.pch文件

2024-06-01 03:38
文章标签 pch profile

本文主要是介绍profile.pch文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


新建Other里面不是有建.pch文件的吗?加进去的话,进入Build setting->Apple LLVM 6.0 -Language ->Precomplile Prefix Header 改成YES  下面那个就是路径 

我们知道,每新建立一个工程,比如说HelloWord,在分类SupportingFiles里都会有一个以工程名开头-Prefix.pch结尾的文件,如HelloWord-Prefix.pch。对于这个文件,很长一段时间里笔者都没觉得它碍事。直到有一天笔者学习NSLog看网上的教程,大家是怎样在最终提交应用的时候,一次性将NSLog语句移除。
网上大多转来转去的方法,都是说把如下的语句

#ifdef DEBUG
#    define DLog(...) NSLog(__VA_ARGS__)
#else
#    define DLog(...) /* */
#endif
#define ALog(...) NSLog(__VA_ARGS__)


加到 <AppName>-Prefix.pch的文件中。虽然对于这种作法,笔者最终由于,不想在调试一个东西而出现一堆东西,最终没有使用这种方法。但是 <AppName>-Prefix.pch这个文件,最终引起了作者的注意。
网上查了一下有解释说.pch是“precompiled header”的意思,那么字面意思理解就是预编译文件头喽。据说在程序编译前都优先编译好这里指定的文件,这样可以加快编译速度。好吧,我们来看看默认这个文件里包含什么:

//
// Prefix header for all source files of the 'HelloWorld' target in the 'HelloWorld' 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>
#endif

按着Command键,再点开UIKit/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>

举个例子,有没有注意到#import <UIKit/UILabel.h>?笔者在使用如下语句的时候:

UILabel *_testLabel = [UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 15)];

曾经不止一次的怀疑,这个UILabel是哪来的,为嘛可以直接用。这个文件就说明了一切!
对此你有什么想法?我的想法就是:如果我每个View几乎都要用到ASIHTTPRequest的话,那么我只在这里引用一次ASIHTTPRequest.h就够了!
这样我就可以在需要使用的ASIHTTPRequest的时候直接用了!
于是我工程里的这个文件变成了这样:

//
// Prefix header for all source files of the 'HelloWorld' target in the 'HelloWorld' project
//

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif

#ifdef __OBJC__
  #import <UIKit/UIKit.h>
  #import <Foundation/Foundation.h>
  #import "nstimer.h"
  #import "ButtWithBlockActions.h"
  #import "TKAlertCenter.h"
  #define TKDCenter [TKAlertCenter defaultCenter] 
  #import "DataManager.h"
  #define DDManager [DataManager defaultManager]
  #define DataMemDic [DDManager memDic]
  //for checkUpdateVersion
  #import "Reachability.h"
  #import "ASIHTTPRequest.h"
  #import "ASIFormDataRequest.h"
  #import "JSON.h"
  
  //BlockAlert
  #import "RIButtonItem.h"
  #import "UIAlertView+Blocks.h"
  #import "UIActionSheet+Blocks.h"

  #import <QuartzCore/QuartzCore.h>
  #import "function.h"
  #import "MediaPlayer/MediaPlayer.h"
#endif

这样的话,我觉得的TKAlertCenter神马的,用起来顺手多了,再也不用每次使用的时候先引用一下了。
注意到上面的

#import "TKAlertCenter.h"
  #define TKDCenter [TKAlertCenter defaultCenter]

没?我觉得每次都写:

[[TKAlertCenter defaultCenter] postAlertWithMessage:@"http://blog.cnrainbird.com"];

这样的句子太长了!有了上面的定义,我现在变成这样写了:

[TKDCenter postAlertWithMessage:@"http://blog.cnrainbird.com"];

是不是短多了?
同样了,我的每个工程的-Prefix.pch文件里还定义了如下的变量:

#define NDSUD [NSUserDefaults standardUserDefaults]
#define NNCDC [NSNotificationCenter defaultCenter]
#define FM [NSFileManager defaultManager]
#define APPSHAREAPP [UIApplication sharedApplication]
#define appOrientation [[UIApplication sharedApplication] statusBarOrientation]
#define DocumentPath [NSString stringWithFormat:@"%@/Library/Caches",NSHomeDirectory()]
#define IOSSystemVersion [[[UIDevice currentDevice] systemVersion] floatValue]

这样做有两个好处:
1.变量名变短了。
虽然object-c里强调变量要完整的表达意思,但是类似[NSUserDefaults standardUserDefaults]这样的单例实在太长了,参数名再长点儿一行都写不下了,很不易于阅读。
2.方便修改
看到DocumentPath这个变量没?大家伙还都记得的IOS5刚出来那会儿,N多app因为把存放文件的路径搁到了Documents下App升级被拒的事儿吧?当时因为我已经用上了这个变量,直接在这个一改,嘿嘿,几十个文件立马跟着变了,省力更省心!

最后发张图,证明我的存在:

这篇关于profile.pch文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1019889

相关文章

spring boot 使用profile来分区配置

很多时候,我们项目在开发环境和生成环境的环境配置是不一样的,例如,数据库配置,在开发的时候,我们一般用测试数据库,而在生产环境的时候,我们是用正式的数据,这时候,我们可以利用profile在不同的环境下配置用不同的配置文件或者不同的配置 spring boot允许你通过命名约定按照一定的格式(application-{profile}.properties)来定义多个配置文件,然后通过在ap

启动浏览器、设置profile加载插件

一、Driver下载地址:   http://docs.seleniumhq.org/download/ 二、启动firefox浏览器(不需要下载驱动,原生支持) 1、firefox安装在默认路径下: 1 //启动默认安装路径下的ff2 public void StartFireFoxByDefault(){3 System.out.printl

为什么我使用source /etc/profile这个命令之后,新的环境变量只能在一个终端里面有效? 为什么我使用source /etc/profile这个命令之后,新的环境变量只能在一个终端里

为什么我使用source /etc/profile这个命令之后,新的环境变量只能在一个终端里面有效?   为什么我使用source /etc/profile这个命令之后,新的环境变量只能在一个终端里面有效? 各位大虾: 我从网上得知,在ubuntu中,使用source /etc/profile命令可以使新建立的环境变量立刻生效而不用重新启动系统,但是 如题,当我使用source /

Maven Profile按环境打包

在日常开发中,我们项目的开发环境和生产环境以及测试环境往往是不同的,比如:数据库的url等。在项目上生产环境时,就需要修改这些参数,给开发造成不便。 为了解决该问题,Maven 2.0引入了构建配置文件的概念(build profiles)。 它能干什么呢? 假如你的生产环境和开发环境所需环境配置不同,生产环境配置文件是pro.properties,开发环境配置文件是dev.prope

注解详解系列 - @Profile:基于环境的配置切换

注解简介 在今天的注解详解系列中,我们将探讨@Profile注解。@Profile是Spring框架中的一个重要注解,用于根据不同的环境配置有选择性地启用或禁用特定的bean。通过@Profile注解,可以方便地在开发、测试、生产等不同环境中切换配置。 注解定义 @Profile注解用于根据特定的环境配置来有选择性地启用或禁用bean。以下是一个基本的示例: import org.sp

Qt警告处理:libpng warning: iCCP: known incorrect sRGB profile

在 qt中加载某些 png图片会出现:libpng warning: iCCP: known incorrect sRGB profile 告警信息。这个警告主要跟png图片的格式有关,说明libpng库的支持还不是很好。 解决办法: (1)使用QImage对图片进行处理一下。 例子: QImage img;img.load("icon.png");img.save("icon.png

SpringBoot学习(三)--Spring profile多环境方式实现logback日志配置

版权声明:作者原创,转载请注明出处。 本系列文章目录地址:http://blog.csdn.net/u011961421/article/details/79416510 继上一篇搭建基础web开发框架后,继续学习和完善项目工程。SpringBoot集成了logback,所以只需要配置一下就可以,这里使用自带Spring profile方式进行多环境配置。 简介 Spring pro

APM Profile 在系统可观测体系中的应用

引言 应用程序性能分析(Application Performance Management,APM)是一个广泛的概念,涉及应用程序运行时各种性能指标的监测、诊断和优化。在可观测体系建设中,APM 是保障系统业务运行性能的关键技术,确保用户可以借助可观测技术手段,感知并发现以往监控工具难以发现的应用运行过程中隐藏的问题。 应用性能分析的主要场景 当我们应用观测云系统进行分析和监控时,采集到的

Maven学习笔记(十二)-使用maven Profile实现多环境构建

1、为什么要使用Profile 在开发过程中,我们的软件会面对不同的运行环境,比如开发环境、测试环境、生产环境,而我们的软件在不同的环境中,有的配置可能会不一样,比如数据源配置、日志文件配置、以及一些软件运行过程中的基本配置,那每次我们将软件部署到不同的环境时,都需要修改相应的配置文件,这样来回修改,是个很麻烦的事情,为了简化和规范这些参数配置,需要对其进行统一规范管理,此时maven提供

XXX File has been modified since the precompiled header 'XXXXXXX-Prefix.pch.gch' was built

XXX File has been modified since the precompiled header ‘XXXXXXX-Prefix.pch.gch’ was built 今天运行公司的SDK,在对外提供的.h文件中改了某些东西又删除了,但是运行的时候报上面的error,对于没有接触过Prefix.pch文件的人来说,当时是要研究一下啦。 1、Prefix.pch文件作用是什么?