ios开发--常用宏定义(部分转)
2015-03-31 14:33
337 查看
1、release时,屏蔽log
C代码
#if defined (DEBUG) && DEBUG == 1
#else
#define NSLog(...) {};
#endif
2、在主线程或在后台执行block
C代码
#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)
3、设备相关
C代码
#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)
#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
4、区分模拟器和真机
C代码
#if TARGET_OS_IPHONE
//iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif
5、根据是否使用ARC做不同操作
C代码
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif
C代码
#if defined (DEBUG) && DEBUG == 1
#else
#define NSLog(...) {};
#endif
#if defined (DEBUG) && DEBUG == 1 #else #define NSLog(...) {}; #endif
2、在主线程或在后台执行block
C代码
#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)
#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)
3、设备相关
C代码
#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)
#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
#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) #define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion]) #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
4、区分模拟器和真机
C代码
#if TARGET_OS_IPHONE
//iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif
#if TARGET_OS_IPHONE //iPhone Device #endif #if TARGET_IPHONE_SIMULATOR //iPhone Simulator #endif
5、根据是否使用ARC做不同操作
C代码
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif
相关文章推荐
- ios开发--常用宏定义(部分转)
- IOS开发中常用到的宏定义
- IOS 程序员开发最常用宏定义
- iOS开发常用宏定义
- iOS之 开发常用到的宏定义
- iOS-为方便项目开发在pch添加一些常用宏定义
- IOS 程序员开发最常用宏定义
- iOS开发常用宏定义
- IOS开发常用宏定义
- IOS开发笔记之常用的宏定义
- iOS开发中的常用宏定义
- IOS 程序员开发最常用宏定义
- iOS开发常用的宏定义
- IOS开发常用宏定义的总结
- iOS敏捷开发之道,常用的宏定义总结
- IOS开发中常用的单例模式宏定义
- IOS开发常用宏定义
- IOS 程序员开发最常用宏定义
- IOS开发中常用的宏定义
- IOS开发中 常用的宏定义[陆续更新]