PCH文件

作者: wpf_register | 来源:发表于2016-07-26 23:56 被阅读34次

    创建pch文件

    1. 新建pch文件
    2. building setting --> Prefix Header 的路径设置为
      $(SRCROOT)/(#项目主文件夹#)/<#prejectName#>.pch
    3. 将Precompile Prefix Header为YES,可以提高编译速度

    pch文件中常用的宏

    • 屏蔽输出日志
    #define NSLog(...)   NSLog(__VA_ARGS__)
    //不需要输出时只要改成 
    #define NSLog(...)    //NSLog(__VA_ARGS__)
    

    #ifdef DEBUG
    // (...) 为固定写法表示可以接受任意多个参数
    #define NSLog(...) NSLog(__VA_ARGS__)
    #else
    #define NSLog(...)
    #endif
    

    //一般在release模式下会定义__OPTIMIZE__,debug模式下不会
    #ifndef __OPTIMIZE__ 
    #define NSLog(...) NSLog(__VA_ARGS__)
    #else
    #define NSLog(...)
    #endif
    

    Xcode 调试程序时,分为Debug和Release,后者不包含任何调试信息,所以体积小,运行速度快。
    项目名 -> Product -> Scheme -> Edit Scheme -> Info ->Build Configuration:选择Debug/Release

    • 确保OC文件引用.h文件
    #ifdef __OBJC__
    //pch 文件导入头文件时,最好确保只有OC文件才可会导入这头文件
    #import "Macro.h"
    #import "Address.h"
    #import "UIFont+appFont.h"
    #endif
    

    相关文章

      网友评论

          本文标题:PCH文件

          本文链接:https://www.haomeiwen.com/subject/djnnjttx.html