美文网首页
iOS_预处理命令

iOS_预处理命令

作者: 莫_名 | 来源:发表于2016-09-08 14:24 被阅读0次
    • 宏定义(执行原理就是直接查找替换)
      • 被代表的部分多行时可使用\号连接
      • #define PI 3.1415926
        • 定义以后作用域直到代码结束
      • 带参宏定义:
        • #define pingFang(a) a*a
        • #define SingleH(name) +(instancetype)share##name;
      • # undef 宏名称
        • 指明结束宏定义作用域

    • 文件导入
      • #include 直接插入,不判断是否已存在
      • #import 自动判断是否已引入过,避免重复导入

    • 条件编译
      • #ifdef , #ifndef , #else , #endif
      • #if , #elif , #else , #endif
    #ifdef __OBJC__
    //只在OC文件中使用宏定义中的内容
    #endif
    
    -------------------------------------------
    
    //如果已经包含了CoreImage.h文件
    #if __has_include(<CoreImage/CoreImage.h>)
    #import <CoreImage/CoreImage.h>
    #endif
    
    -------------------------------------------
    
    #ifdef  DEBUG
      //调试阶段
      #define DebugLog(...)  NSLog(__VA_ARGS__);
      #define DebugMethod  NSLog(@"%s",__func__);
    #else
      //发布阶段
      #define DebugLog(...)
      #define DebugMethod 
    #endif
    
    -------------------------------------------
    
    //在代码中打标记(-表示是否带分割线)
    #pragma mark - 随机颜色创建
    #pragma mark  随机颜色创建
    #warning xxxx
    #error  xxxxx
    
    --------------------------------------------
    
    #if __has_feature(objc_arc)
    //所在文件使用ARC
    #else
    //所在文件使用MRC
    #endif
    
    
    
    
    

    相关文章

      网友评论

          本文标题:iOS_预处理命令

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