http://my.oschina.net/yongbin45/blog/150149

// 字符串:
#ifndef nilToEmpty
#define nilToEmpty(object) (object!=nil)?object:@""
#endif

#ifndef formatStringOfObject
#define formatStringOfObject(object) [NSString stringWithFormat:@"%@", object]
#endif

#ifndef nilToEmptyFormatStringOfObject
#define nilToEmptyFormatStringOfObject(object) formatStringOfObject(nilToEmpty(object))
#endif

// 图片:
#ifndef imagePath
#define imagePath(imageName) [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]
#endif

// 颜色
#define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r, g, b) RGBA(r, g, b, 1.0f)
#define HEXCOLOR(c) [UIColor colorWithRed:((c>>16)&0xFF)/255.0f green:((c>>8)&0xFF)/255.0f blue:(c&0xFF)/255.0f alpha:1.0f];

// debug
#define debug(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])

// iOS 支持
#define SUPPORT_IPHONE_OS_VERSION(version) ( __IPHONE_OS_VERSION_MIN_REQUIRED <= version && __IPHONE_OS_VERSION_MAX_ALLOWED >= version)

// Application delegate
#define ApplicationDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])

// 主要单例
#define UserDefaults [NSUserDefaults standardUserDefaults]
#define NotificationCenter [NSNotificationCenter defaultCenter]
#define SharedApplication [UIApplication sharedApplication]

#define Bundle [NSBundle mainBundle]

#define MainScreen [UIScreen mainScreen]

// 网络指示
#define ShowNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = YES
#define HideNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = NO
#define NetworkActivityIndicatorVisible(x) [UIApplication sharedApplication].networkActivityIndicatorVisible = x

// 主要控件
#define NavBar self.navigationController.navigationBar
#define TabBar self.tabBarController.tabBar

// 大小尺寸
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width
#define ScreenHeight [[UIScreen mainScreen] bounds].size.height

#define NavBarHeight self.navigationController.navigationBar.bounds.size.height
#define TabBarHeight self.tabBarController.tabBar.bounds.size.height

#define TouchHeightDefault 44.0f
#define TouchHeightSmall 32.0f

#define ViewWidth(v) v.frame.size.width
#define ViewHeight(v) v.frame.size.height
#define ViewX(v) v.frame.origin.x
#define ViewY(v) v.frame.origin.y

#define SelfViewWidth self.view.bounds.size.width
#define SelfViewHeight self.view.bounds.size.height

#define RectX(rect) rect.origin.x
#define RectY(rect) rect.origin.y
#define RectWidth(rect) rect.size.width
#define RectHeight(rect) rect.size.height

#define RectSetWidth(rect, w) CGRectMake(RectX(rect), RectY(rect), w, RectHeight(rect))
#define RectSetHeight(rect, h) CGRectMake(RectX(rect), RectY(rect), RectWidth(rect), h)
#define RectSetX(rect, x) CGRectMake(x, RectY(rect), RectWidth(rect), RectHeight(rect))
#define RectSetY(rect, y) CGRectMake(RectX(rect), y, RectWidth(rect), RectHeight(rect))

#define RectSetSize(rect, w, h) CGRectMake(RectX(rect), RectY(rect), w, h)
#define RectSetOrigin(rect, x, y) CGRectMake(x, y, RectWidth(rect), RectHeight(rect))

// 内存管理
#if ! __has_feature(objc_arc)
#define SBAutorelease(__v) ([__v autorelease]);
#define SBReturnAutoreleased SBAutorelease

#define SBRetain(__v) ([__v retain]);
#define SBReturnRetained SBRetain

#define SBRelease(__v) ([__v release]);

#define SBDispatchQueueRelease(__v) (dispatch_release(__v));
#else
// -fobjc-arc
#define SBAutorelease(__v)
#define SBReturnAutoreleased(__v) (__v)

#define SBRetain(__v)
#define SBReturnRetained(__v) (__v)

#define SBRelease(__v)

#if TARGET_OS_IPHONE
// Compiling for iOS
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000
// iOS 6.0 or later
#define SBDispatchQueueRelease(__v)
#else
// iOS 5.X or earlier
#define SBDispatchQueueRelease(__v) (dispatch_release(__v));
#endif
#else
// Compiling for Mac OS X
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
// Mac OS X 10.8 or later
#define SBDispatchQueueRelease(__v)
#else
// Mac OS X 10.7 or earlier
#define SBDispatchQueueRelease(__v) (dispatch_release(__v));
#endif
#endif
#endif

iOS 多快好省的宏定义的更多相关文章

  1. iOS技巧,宏定义

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnoAAAPCCAYAAADvRHWgAAAAAXNSR0IArs4c6QAAAZ1pVFh0WE1MOm

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

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

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

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

  4. iOS之常用宏定义

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

  5. iOS - 常用的宏定义

    1.处理NSLog事件(开发者模式打印,发布者模式不打印) 1 2 3 4 5   #ifdef DEBUG   #define NSLog(FORMAT, ...) fprintf(stderr,& ...

  6. iOS常用的宏定义总结

    字符串是否为空 1   #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str le ...

  7. iOS swift 常量 && 宏定义

    全局常量 在C和Objective-C语言源文件中定义的全局常量会自动地被Swift编译引进并做为Swift的全局常量. 预处理指令 Swift编译器不包含预处理器.取而代之的是,它充分利用了编译时属 ...

  8. IOS 常用的宏定义(#define)

    开发中经常用到的常量定义(随时更行): 与UIView相关 //获取View的frame属性 #define GetViewWidth(view) view.frame.size.width #def ...

  9. ios 随机色 宏定义

    #define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1] #d ...

随机推荐

  1. centos 7 安装 python-dev包提示No package python-dev available

    centos安装 python-dev包提示No package python-dev available: 出现此问题的原因是python-dev的包在centos的yum中不叫python-dev ...

  2. JSVirtualMachine与JSContext

    JSVirtualMachine相当于进程: JSContext相当于线程:

  3. python中的IO多路复用

    在python的网络编程里,socetserver是个重要的内置模块,其在内部其实就是利用了I/O多路复用.多线程和多进程技术,实现了并发通信.与多进程和多线程相比,I/O多路复用的系统开销小,系统不 ...

  4. ecshop 多表删除

    $sql = 'DELETE O, G FROM ' . $GLOBALS['ecs']->table('delivery_order') . ' AS O, ' . $GLOBALS['ecs ...

  5. RDBMS DML DDL

    RDBMS RDBMS 指的是关系型数据库管理系统. RDBMS 是 SQL 的基础,同样也是所有现代数据库系统的基础,比如 MS SQL Server, IBM DB2, Oracle, MySQL ...

  6. ORACLE 触发器

    •1.1 触发器类型 • DML触发器 • 替代触发器 • 系统触发器 •1.2 创建触发器 • 触发器触发次序 • 创建DML触发器 • 创建替代(INSTEAD OF)触发器 • 创建系统事件触发 ...

  7. C#模拟鼠标键盘控制其他窗口(一)

    编写程序模拟鼠标和键盘操作可以方便的实现你需要的功能,而不需要对方程序为你开放接口.比如,操作飞信定时发送短信等.我之前开发过飞信耗子,用的是对飞信协议进行抓包,然后分析协议,进而模拟协议的执行,开发 ...

  8. [Search Engine] 搜索引擎技术之倒排索引

    倒排索引是搜索引擎中最为核心的一项技术之一,可以说是搜索引擎的基石.可以说正是有了倒排索引技术,搜索引擎才能有效率的进行数据库查找.删除等操作. 1. 倒排索引的思想 倒排索引源于实际应用中需要根据属 ...

  9. php glob()函数实现目录文件遍历与寻找与模式匹配的文件路径

    采用PHP函数glob实现寻找与模式匹配的文件路径,主要讨论glob()函数的作用和用法,利用glob函数读取目录比其它的要快N倍,因为glob函数是内置函数处理起来自然要快. 一,函数原型 arra ...

  10. PHP函数 addslashes() 和 mysql_real_escape_string() 的区别 && SQL宽字节,绕过单引号注入攻击

    首先:不要使用 mysql_escape_string(),它已被弃用,请使用 mysql_real_escape_string() 代替它. mysql_real_escape_string() 和 ...