![[Cocoa] 定制 Prefix.pch文件,第1张 [Cocoa] 定制 Prefix.pch文件,第1张](/aiimages/%5BCocoa%5D+%E5%AE%9A%E5%88%B6+Prefix.pch%E6%96%87%E4%BB%B6.png)
[Cocoa] 定制 Prefix.pch文件
罗朝辉(http://blog.csdn.net/kesalin/)
CC许可,转载请注明出处
扩展名 pch 表示 “precompliled header”,即预编译头文件,prefix.pch 为 XCode 工程默认生成的预编译头文件,在其中我们可以定制一些全局的宏,以方便开发。
下面贴一段来自 Cocoa Is My Girlfriend 定制的宏:
#ifdef DEBUG #define DLog(...) NSLog(@"%s %@",__PRETTY_FUNCTION__,[Nsstring stringWithFormat:__VA_ARGS__]) #define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[Nsstring stringWithCString:__PRETTY_FUNCTION__ enCoding:NSUTF8StringEnCoding] file:[Nsstring stringWithCString:__file__ enCoding:NSUTF8StringEnCoding] lineNumber:__liNE__ description:__VA_ARGS__]#else #define DLog(...) do { } while (0) #ifndef NS_BLOCK_ASSERTIONS #define NS_BLOCK_ASSERTIONS #endif #define ALog(...) NSLog(@"%s %@",[Nsstring stringWithFormat:__VA_ARGS__])#endif #define ZAssert(condition,...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0) 详细解说请阅读 原文,在这里我只说明其用法:
1,如果是 deBUG 模式下,需要在编译选项 Preprocessor Macros 中设置 DEBUG 宏;
2,DLog 相当于 NSLog,但只在 deBUG 模式下有效;在 release 模式下,它什么也不做;
3,ALog 是 Assert Log 的简写,在 deBUG 模式下,相当于强制 assert;在 release 模式下,相当于 NSLog;
4,ZAssert 是带有条件判断的 ALog;
参考资料:
My current Prefix.pch file
以上是内存溢出为你收集整理的[Cocoa] 定制 Prefix.pch文件全部内容,希望文章能够帮你解决[Cocoa] 定制 Prefix.pch文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)