- NSLog宏
#define NSLog(format, ...) do { \
fprintf(stderr," %s\n", \[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
__LINE__, __func__); \
(NSLog)((format), ##__VA_ARGS__); \
fprintf(stderr, "-------\n"); \
} while (0)
- 打印方法名
#define ZZDPRINTMETHODNAME() ZZDPRINT(@"%s", __PRETTY_FUNCTION__)
- Debug
#ifdef ZZDEBUG
#define ZZDCONDITIONLOG(condition, xx, ...) { if ((condition)) { \
ITTDPRINT(xx, ##__VA_ARGS__); \
} \
} ((void)0)
#else
#define ZZDCONDITIONLOG(condition, xx, ...) ((void)0)
#endif
- 错误抛出
#define DgAssert(condition, ...)\
do {\
if (!(condition)) {\
[[NSAssertionHandler currentHandler]\
handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
file:[NSString stringWithUTF8String:__FILE__]\
lineNumber:__LINE__\
description:__VA_ARGS__];\
}\
} while(0)
- 测试方法或代码执行时间
#define TICK NSDate *startTime = [NSDate date]
#define TOCK NSLog(@"Time: %f", [startTime timeIntervalSinceNow])
- 定义编译环境
#ifndef __OPTIMIZE__
//这里执行的是debug模式下
else
//这里执行的是release模式下
#endif
//都注释为UAT环境
#define SERVER_PRODUCT_SWITCH // 生成地址 放开为生产地址
#define TEST_SERVER_SWITCH // 测试地址 放开为测试地址
#ifdef SERVER_PRODUCT_SWITCH //——线上地址
//define something
//MARK: 测试地址
#elif defined TEST_SERVER_SWITCH
//define something
//MARK: UAT
#else // UAT
//define something
#endif
- 模拟器或真机判断
#if defined (__i386__) || defined (__x86_64__)
//模拟器下执行
#else
//真机下执行
#endif
- RGB颜色
#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)]
- 角度弧度互换
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)
- 字符串操作
#define IS_STRING_NOT_EMPTY(sting)(sting && ![@"" isEqualToString:sting] && (NSNull *)sting!=[NSNull null])
#define IS_STRING_EMPTY(sting)(!sting || [@"" isEqualToString:sting] || (NSNull *)sting==[NSNull null])
#define SAFE_STRING(x)(IS_STRING_EMPTY(x))?(@""):(x)
- 随机数
#define RANDOM_SEED() srandom(time(NULL))
#define RANDOM_INT(__MIN__, __MAX__) ((__MIN__) + random() % ((__MAX__+1) - (__MIN__)))