美文网首页
iOS常用宏

iOS常用宏

作者: lele8446 | 来源:发表于2016-01-13 16:23 被阅读78次
设置NSLog
以release模式编译的程序不会用NSLog输出,而以debug模式编译的程序将执行NSLog的全部功能。
  #ifndef __OPTIMIZE__
   # define NSLog(...) NSLog(__VA_ARGS__)
   #else
   # define NSLog(...)
   #endif
判空
   #define isNull(a)  (a==nil || a==NULL || (NSNull *)(a)==[NSNull null] || ((NSString *)a).length==0)
快速设置颜色
   #define CJColor(r,g,b,a) ([UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a])
沙盒document路径
   #define DOCUMENT_DIRECTORY ([NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0])
沙盒cache路径
   #define CACHE_DIRECTORY ([NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0])
当期系统版本
   #define IOS_VERSION ([[[UIDevice currentDevice] systemVersion] floatValue])
获取屏幕宽高
   #define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
   #define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
获取GCD主线程队列
   #define dispatch_async_main_queue(block)\
         if ([NSThread isMainThread]) {\
             block();\
         } else {\
             dispatch_async(dispatch_get_main_queue(), block);\
         }

相关文章

网友评论

      本文标题:iOS常用宏

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