常用的宏定义

//字符串是否为空

#definekStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] <1? YES : NO )

//数组是否为空

#definekArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count ==0)

//字典是否为空

#definekDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys ==0)

//是否是空对象

#definekObjectIsEmpty(_object) (_object == nil \|| [_object isKindOfClass:[NSNull class]] \|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] ==0) \|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] ==0))

//获取屏幕宽度与高度

#definekScreenWidth \([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)

#definekScreenHeight \([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)

#definekScreenSize \([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size)

//一些缩写

#definekApplication        [UIApplication sharedApplication]

#definekKeyWindow          [UIApplication sharedApplication].keyWindow

#definekAppDelegate        [UIApplication sharedApplication].delegate#definekUserDefaults      [NSUserDefaults standardUserDefaults]

#definekNotificationCenter [NSNotificationCenter defaultCenter]

//APP版本号

#definekAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//系统版本号

#definekSystemVersion [[UIDevice currentDevice] systemVersion]

//获取当前语言

#definekCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

//判断是否为iPhone

#definekISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

//判断是否为iPad

#definekISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

//获取沙盒Document路径

#definekDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

//获取沙盒temp路径

#definekTempPath NSTemporaryDirectory()

//获取沙盒Cache路径

#definekCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

//判断是真机还是模拟器

#ifTARGET_OS_IPHONE

//真机

#endif

#ifTARGET_IPHONE_SIMULATOR

//模拟器#endif//开发的时候打印,但是发布的时候不打印的NSLog

#ifdefDEBUG

#define

NSLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])

#else#defineNSLog(...)

#endif

//颜色

#definekRGBColor(r, g, b)    [UIColor colorWithRed:(r)/255.0green:(g)/255.0blue:(b)/255.0alpha:1.0]

#definekRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0green:(r)/255.0blue:(r)/255.0alpha:a]#definekRandomColor  KRGBColor(arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0)

#definekColorWithHex(rgbValue) \[UIColor colorWithRed:((float)((rgbValue &0xFF0000) >>16)) /255.0\green:((float)((rgbValue &0xFF00) >>8)) /255.0\blue:((float)(rgbValue &0xFF)) /255.0alpha:1.0]

//弱引用/强引用

#definekWeakSelf(type)  __weak typeof(type) weak

##type = type;

#definekStrongSelf(type) __strong typeof(type) type = weak

##type;

//由角度转换弧度

#definekDegreesToRadian(x)      (M_PI * (x) /180.0)

//由弧度转换角度

#definekRadianToDegrees(radian) (radian *180.0) / (M_PI)//获取一段时间间隔#definekStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();

#definekEndTime  NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)

你可能感兴趣的:(常用的宏定义)