iOS开发常用的宏
来源:互联网 发布:vim c语言高亮 编辑:程序博客网 时间:2024/05/16 10:51
//字符串是否为空#define lStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO ) //数组是否为空#define lArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0) //字典是否为空#define lDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0) //是否是空对象#define lObjectIsEmpty(_object) (_object == nil \|| [_object isKindOfClass:[NSNull class]] \|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0)) //获取屏幕宽度与高度#define lScreenWidth \([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)#define lScreenHeight \([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)#define lScreenSize \([[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) //一些缩写#define lApplication [UIApplication sharedApplication]#define lKeyWindow [UIApplication sharedApplication].keyWindow#define kAppDelegate [UIApplication sharedApplication].delegate#define lUserDefaults [NSUserDefaults standardUserDefaults]#define lNotificationCenter [NSNotificationCenter defaultCenter] //APP版本号#define lAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] //系统版本号#define lSystemVersion [[UIDevice currentDevice] systemVersion] //获取当前语言#define lCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) //判断是否为iPhone#define lISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) //判断是否为iPad#define lISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //获取沙盒Document路径#define lDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] //获取沙盒temp路径#define lTempPath NSTemporaryDirectory() //获取沙盒Cache路径#define lCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] //判断是真机还是模拟器#if TARGET_OS_IPHONE//真机#endif#if TARGET_IPHONE_SIMULATOR//模拟器#endif //开发的时候打印,但是发布的时候不打印的NSLog#ifdef DEBUG#define NSLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])#else#define NSLog(...)#endif //颜色#define lRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]#define lRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]#define lRandomColor KRGBColor(arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0)#define lColorWithHex(rgbValue) \[UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 \green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 \blue:((float)(rgbValue & 0xFF)) / 255.0 alpha:1.0] //弱引用/强引用#define lWeakSelf(type) __weak typeof(type) weak##type = type;#define lStrongSelf(type) __strong typeof(type) type = weak##type; //由角度转换弧度#define lDegreesToRadian(x) (M_PI * (x) / 180.0) //由弧度转换角度#define lRadianToDegrees(radian) (radian * 180.0) / (M_PI) //获取一段时间间隔#define lStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();#define lEndTime NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)
0 0
- iOS开发常用的宏
- ios开发常用的宏
- iOS开发常用的宏
- iOS开发常用的宏
- iOS开发常用的宏
- ios开发常用的宏
- ios开发常用的宏
- ios开发常用的宏
- ios开发常用的宏
- ios开发常用的宏
- ios开发常用的宏
- iOS开发常用的宏
- iOS开发-常用的宏
- iOS开发常用的宏
- iOS开发常用的宏
- iOS开发常用的宏
- iOS开发常用宏
- iOS开发常用宏
- HTTP状态码
- nginx学习(十二)——nginx+lua入门
- Centos 6.5 Install KVM
- 文智背后的奥秘系列篇——情感分类
- 5.2 图的存储及基本操作
- iOS开发常用的宏
- 自定义xml解析框架
- activity与fragment中使用OnActivityResult方法
- Netty 初步介绍
- Android系统应用开发(八)ANR应用程序与无响应对话框自定义
- 用RNN拟合加法运算
- 从数据库获取数据插入页面
- mongoDB常用命令
- 数据管理工具中的1130错误的解决方法