zoukankan      html  css  js  c++  java
  • [Cocoa]XCode中定制Prefix.pch文件

    XCode中定制Prefix.pch文件

    罗朝辉 (http://www.cnblogs.com/kesalin/)

    本文遵循“署名-非商业用途-保持一致”创作公用协议


    扩展名 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 %@", __PRETTY_FUNCTION__, [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


  • 相关阅读:
    CSS基础(十七)--Padding和margin(内边距和外边距)
    tomcat动态网站
    http和nginx错误定义
    nginx动态网站
    nginx动静分离
    nginx负载均衡
    nginx介绍
    cobbler服务器
    apache网络配置
    网络源
  • 原文地址:https://www.cnblogs.com/kesalin/p/xcode_pefix.html
Copyright © 2011-2022 走看看