在项目里.pch 文件最后加入我们想要定义的宏就可以了,在整个项目中我们都可以使用这些宏。
#pragma mark - safe release
/*
* 释放内存
*/
#define RELEASE(_Ptr)\
if (_Ptr)\
{\
[_Ptr release];\
_Ptr = nil;\
}
#pragma mark - width and height
/*
* 屏幕尺寸,APP尺寸
*/
#define SCREEEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define APPFRAME_WIDTH [UIScreen mainScreen].applicationFrame.size.width
#define APPFRAME_HEIGHT [UIScreen mainScreen].applicationFrame.size.height
#pragma mark - iPhone or iPad
/*
* 是否是iPhone或iPad
*/
#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)
#pragma mark - ios system
/*
* 系统版本,偏好语言
*/
#define IOS_VERSION [[UIDevice currentDevice].systemVersion floatValue]
#define PREFERRED_LANGUAGE ([[NSLocale preferredLanguages] objectAtIndex:0])
#pragma mark - color functions
/*
* 颜色运算
*/
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1];
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)];
#pragma mark - nsnotification
/*
* 订阅/取消消息通知
*/
#define Add_Notification(selectorName, notificationName) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectorName) name:notificationName object:nil];
#define Remove_Notification(notificationName) [[NSNotificationCenter defaultCenter] removeObserver:self name:notificationName object:nil];
#pragma mark - debug
/*
* 打印debug信息
*/
//use dlog to print while in debug model
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
#pragma mark - ARC
/*
*是否使用了ARC
*/
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif
#pragma mark - GCD
/*
*GCD
*/
#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)