常用宏定义 #define
来源:互联网 发布:石大在线网络教育 编辑:程序博客网 时间:2024/05/01 19:34
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)
//Device
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
谢谢16楼提出的 “判断Retina设备建议使用[[UIScreen mainScreen] scale]==2,不然横屏下那个宏定义判断的有问题 ”
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//区分模拟器和真机
#if TARGET_OS_IPHONE
//iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif
//ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif
#define USER_DEFAULT [NSUserDefaults standardUserDefaults]
#define DATA_ENV [DataEnvironment sharedDataEnvironment]
#define ImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]]
////////////////////////////////////////////////////////////////////////////////
#pragma mark - common functions
#define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }
////////////////////////////////////////////////////////////////////////////////
#pragma mark - degrees/radian functions
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)
////////////////////////////////////////////////////////////////////////////////
#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)]
#define ITTDEBUG
#define ITTLOGLEVEL_INFO 10
#define ITTLOGLEVEL_WARNING 3
#define ITTLOGLEVEL_ERROR 1
#ifndef ITTMAXLOGLEVEL
#ifdef DEBUG
#define ITTMAXLOGLEVEL ITTLOGLEVEL_INFO
#else
#define ITTMAXLOGLEVEL ITTLOGLEVEL_ERROR
#endif
#endif
// The general purpose logger. This ignores logging levels.
#ifdef ITTDEBUG
#define ITTDPRINT(xx, ...) NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define ITTDPRINT(xx, ...) ((void)0)
#endif
// Prints the current method's name.
#define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s", __PRETTY_FUNCTION__)
// Log-level based logging macros.
#if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL
#define ITTDERROR(xx, ...) ITTDPRINT(xx, ##__VA_ARGS__)
#else
#define ITTDERROR(xx, ...) ((void)0)
#endif
#if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL
#define ITTDWARNING(xx, ...) ITTDPRINT(xx, ##__VA_ARGS__)
#else
#define ITTDWARNING(xx, ...) ((void)0)
#endif
#if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL
#define ITTDINFO(xx, ...) ITTDPRINT(xx, ##__VA_ARGS__)
#else
#define ITTDINFO(xx, ...) ((void)0)
#endif
#ifdef ITTDEBUG
#define ITTDCONDITIONLOG(condition, xx, ...) { if ((condition)) { \
ITTDPRINT(xx, ##__VA_ARGS__); \
} \
} ((void)0)
#else
#define ITTDCONDITIONLOG(condition, xx, ...) ((void)0)
#endif
#define ITTAssert(condition, ...) \
do { \
if (!(condition)) { \
[[NSAssertionHandler currentHandler] \
handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
file:[NSString stringWithUTF8String:__FILE__] \
lineNumber:__LINE__ \
description:__VA_ARGS__]; \
} \
} while(0)
7.单例
// @interface
#define singleton_interface(className) \
+ (className *)shared##className;
// @implementation
#define singleton_implementation(className) \
static
className *_instance; \
+ (id)allocWithZone:(struct _NSZone *)zone \
{ \
static
dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [
super
allocWithZone:zone]; \
}); \
return
_instance; \
} \
+ (className *)shared##className \
{ \
static
dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [[self alloc] init]; \
}); \
return
_instance; \
}
- 常用宏定义 #define
- C++工程中常用的宏定义(#define)
- 宏定义define用法
- 宏定义#define
- Embedded - Define 宏定义
- 使用宏定义DEFINE
- #define宏定义中的#,##,@#,\
- C宏定义#define
- ios #define 宏定义
- 宏定义define
- 宏定义#define
- 宏定义#define整理
- C++宏定义#define
- define宏定义中的#,##
- 058.Define 宏定义
- 宏定义#define
- 关于#define宏定义
- 058.Define 宏定义
- 我在兰亭这三年完结篇之离开
- MaxEnt: 最大熵模型(Maximum Entropy Models)(二)
- 如何防止域名被盗
- JAVA BigDecimal初步学习
- 冒泡排序法(Java)
- 常用宏定义 #define
- UVA - 10305 Ordering Tasks
- 动态内存分配
- 别踩白块儿之禅模式 windows程序实现
- NVL2
- 用华为C8813调试LogCat不显示日志问题解决方法
- iOS中注册功能的体验探究
- NSMutableDictionary 用set方法初始化的字典 里边的键值不可修改
- 国内技术创新型公司的一个问题