#define NSAssert(condition, desc, ...) \
do { \
__PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS \
if (!(condition)) { \
[[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd \
object:self file:[NSString stringWithUTF8String:__FILE__] \
lineNumber:__LINE__ description:(desc), ##__VA_ARGS__]; \
} \
__PRAGMA_POP_NO_EXTRA_ARG_WARNINGS \
} while(0)
通常用来预处理,condition 是条件,desc 是输出的内容
例如:
NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view."); // 用来判断数组元素是否大于1,如果大于一则不输出,反之输出
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)
// 使用案例 列举
SuppressPerformSelectorLeakWarning(
[classViewControllerNavManager performSelector:selNavToSearch withObject:self];
);
// 判断是否是大于7 的系统
#define IsIOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >=7.0 ? YES : NO)
// 用来判断指定版本是否大于指定的版本信息
#define LTAPI_IS_ALLOWED(version) ([[[UIDevice currentDevice] systemVersion] doubleValue] >= version)
//设备屏幕大小
#define __MainScreenFrame [[UIScreen mainScreen] bounds]
//设备屏幕宽
#define __MainScreen_Width ((__MainScreenFrame.size.width)<(__MainScreenFrame.size.height)?(__MainScreenFrame.size.width):(__MainScreenFrame.size.height))
#define __MainScreen_Height ((__MainScreenFrame.size.height)>(__MainScreenFrame.size.width)?(__MainScreenFrame.size.height):(__MainScreenFrame.size.width))
//自动布局使用
#define kRealWidth(d) (d)*((__MainScreen_Width)/320.0)
通过该方法进行一个具体位置的定位功能
//数组越界检处理
#define OBJECT_OF_ATINDEX(_ARRAY_,_INDEX_) ((_ARRAY_)&&[_ARRAY_ isKindOfClass:[NSArray class]]&&(_INDEX_ < [_ARRAY_ count])&&(_INDEX_ >= 0)?([_ARRAY_ objectAtIndex:_INDEX_]):(nil))//有返回值
今后项目里还会陆续补充常用的一些宏的使用。。。。。