IOS开发之----常用宏定义和讲解_IOS-Coding_新浪博客

来源:互联网 发布:网络电视不清晰怎么办 编辑:程序博客网 时间:2024/04/28 22:37

原文地址:http://chenyilong.postach.io/ioskai-fa-zhi-chang-yong-hong-ding-yi-he-jiang-jie-ios-coding-xin-lang-bo-ke?utm_source=tuicool&utm_medium=referral

系统宏汇集

__FILE__  

当前文件所在目录

__DATE__  

“替代文字”是一个含有编译日期的字符串字面值,日期格式为“mm dd yyyy”(例如:“Mar 19 2006”)。如果日期小于10日,就在日的前面放一个空格符。 NSLog ( @”DATE=%s” , DATE );

__FUNCTION__

当前函数名称

__LINE__  

当前语句在源文件中的行数

__TIME__

此字符串字面值包含编译时间,格式为“hh:mm:ss”(范例:“08:00:59”)。

__STDC__

整数常量1,表示此编译器遵循ISOC标准。

__STDC_VERSION__ 

如何实现复合C89整部1,则这个宏的值为19940SL;如果实现符合C99,则这个宏的值为199901L;否则数值是未定义

__STDC_EOBTED__

(C99)实现为宿主实现时为1,实现为独立实现为0

__STDC_IEC_559__ 

(C99)浮点数实现复合IBC 60559标准时定义为1,否者数值是未定义

__STDC_IEC_559_COMPLEX__ 

(C99)复数运算实现复合IBC 60559标准时定义为1,否者数值是未定义

__STDC_ISO_10646__ 

(C99)定义为长整型常量,yyyymmL表示wchar_t值复合ISO 10646标准及其指定年月的修订补充,否则数值未定义

1、release时,屏蔽log

#if  defined  (DEBUG)  &&  DEBUG  ==  1    #else    #define  NSLog(...)  {};    #endif    

2、在主线程或在后台执行block

#define  BACK(block)  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,  0),  block)    #define  MAIN(block)  dispatch_async(dispatch_get_main_queue(),block)    

3、设备相关

#define  isRetina  ([UIScreen  instancesRespondToSelect or:@selector(currentMode)]  ?  CGSizeEqualToSize(CGSizeMake(640,  960),  [[UIScreen  mainScreen]  currentMode].size)  :  NO)    #define  iPhone5  ([UIScreen  instancesRespondToSelect or:@selector(currentMode)]  ?  CGSizeEqualToSize(CGSizeMake(640,  1136),  [[UIScreen  mainScreen]  currentMode].size)  :  NO)    #define  isPad  (UI_USER_INTERFACE_IDIOM()  ==  UIUserInterfaceIdiomPad)    #define  CurrentSystemVersion  ([[UIDevice  currentDevice]  systemVersion])    #define  CurrentLanguage  ([[NSLocale  preferredLanguages]  objectAtIndex:0])     

4、 区分模拟器和真机

#if  TARGET_OS_IPHONE    //iPhone  Device    #endif    #if  TARGET_IPHONE_SIMULATOR    //iPhone  Simulator    #endif    

5、根据是否使用ARC做不同操作

#if  __has_feature(objc_arc)            //compiling  with  ARC    #else            //  compiling  without  ARC    #endif    
0 0