1、release时,屏蔽log

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

#else
#define NSLog(...) {};
#endif

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

  1. #define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
  2. #define MAIN(block) dispatch_async(dispatch_get_main_queue(),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、设备相关

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

#define iPhone5 ([UIScreen instancesRespondToSelector:@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、区分模拟器和真机

  1. #if TARGET_OS_IPHONE
  2. //iPhone Device
  3. #endif
  4. #if TARGET_IPHONE_SIMULATOR
  5. //iPhone Simulator
  6. #endif
#if TARGET_OS_IPHONE
//iPhone Device
#endif #if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif

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

  1. #if __has_feature(objc_arc)
  2. //compiling with ARC
  3. #else
  4. // compiling without ARC
  5. #endif

ios开发--常用宏定义(部分转)的更多相关文章

  1. IOS开发常用宏定义

    //release屏蔽NSLog//放在.pch文件里#ifdef DEBUG #else#define NSLog(...) {};#endif //G.C.D#define BACK(block) ...

  2. iOS开发——常用宏的定义

    有些时候,我们需要将代码简洁化,这样便于读代码.我们可以将一些不变的东东抽取出来,将变化的东西作为参数.定义为宏,这样在写的时候就简单多了. 下面例举了一些常用的宏定义和大家分享: 1. 判断设备的操 ...

  3. iOS开发笔记--宏定义的黑魔法 - 宏菜鸟起飞手册

    宏定义在C系开发中可以说占有举足轻重的作用.底层框架自不必说,为了编译优化和方便,以及跨平台能力,宏被大量使用,可以说底层开发离开define将寸步难行.而在更高层级进行开发时,我们会将更多的重心放在 ...

  4. iOS开发之--宏定义与const的区别及使用方法

    宏定义的常见用法: 定义一段代码,或指定字符串抽成宏. const(常量): 当有字符串常量的时候,苹果推荐我们使用const,苹果经常把常用的字符串定义成const 宏定义与const的区别: 编译 ...

  5. iOS 开发常用宏

    来源:iOS_小松哥 链接:http://www.jianshu.com/p/be00c3f3cafd 大家都是知道使用宏不仅方便,而且可以提高开发效率.下面总结了iOS开发过程中的一些常用宏,会持续 ...

  6. iOS之常用宏定义

    下面我为大家提供一些常用的宏定义! 将这些宏定义 加入到.pch使用 再也不用 用一次写一次这么长的程序了 //-------------------获取设备大小------------------- ...

  7. Object-C开发常用宏定义

    Object-C开发中宏会将经常用到的系统常量进行封装,方便使用: 1.获取通知中心 #define EYNotificationCenter(name, object, userInfo) [[NS ...

  8. ios 日常开发常用宏定义

      #pragma mark - 字体.颜色相关 #define kFONT_SIZE(f) [UIFont systemFontOfSize:(f)] #define kFONT_BOLD_SIZE ...

  9. 李洪强iOS开发之宏定义方法来初始化一个单例对象

    单例的使用: .m 为了方便实用,只要将以下代码定义在header文件或者.pch文件即可: // .h #define singleton_interface(class) + (instancet ...

随机推荐

  1. Centos linux php扩展安装步骤

    使用phpinfo()函数输出PHP信息,然后找到Configuration File (php.ini) apachectl 其设计意图是帮助管理员控制Apache httpd后台守护进程的功能. ...

  2. ASPxGridView中批量提交及个别提交的写法

    //获取chech box ID protected string GetProtoID() { string protoId = ""; //获取选中的记录Id List< ...

  3. ostack

  4. windows live writer向cnblog发布文章设置(转)

    Windows Live Writer是非常不错的一个日志发布工具,支持本地写文章,非常方便将word 中内容,包括图片进行处理,有点感觉相见恨晚. Live Writer最新版本下载地址是什么? h ...

  5. Windows server 2008R2部署服务批量安装Windows7教程

    利用Windows server 2008 R2下的Windows部署服务可以批量安装Windows 7,以下简称WDS. WDS需要用到域和dhcp.DNS服务,所以,基础环境必须要有域控制器,dh ...

  6. leetcode 9

    判断一个数是否为回文数,不利用额外的空间. 思路:将数反转后进行比较. 注意:反转之后数越界的判断,若越界,则不是回文数:负数不是回文数: 代码如下: class Solution { public: ...

  7. 华为OJ—字符串排序(排序,忽略指定字符排序)

    http://career-oj.huawei.com/exam/ShowProblemInfo?id=2168 编写一个程序,将输入字符串中的字符按如下规则排序. 规则1:英文字母从A到Z排列,不区 ...

  8. C 小复习

    C语言 signed 与 unsigned: C语言中,当表达式中存在有符号类型和无符号类型时所有的操作数都自动转换为无符号类型 signed ; unsigned ; cout << a ...

  9. IOS CLLocationManager定位反编码位置信息

    //获取位置和坐标#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1        if (IOS_VERSION >= 8.0) {   ...

  10. 转 网络IO模型:同步IO和异步IO,阻塞IO和非阻塞IO

    此文章为转载,如有侵权,请联系本人.转载出处,http://blog.chinaunix.net/uid-28458801-id-4464639.html 同步(synchronous) IO和异步( ...