NSAssert宏的定义如下,具体看官方文档
#define NSAssert(condition, desc, ...) ...
NSAssert
是IOS里的一个宏定义,通常用来调试,condition
是条件表达式,值为YES
或NO
;desc
为异常描述,通常为NSString
。当conditon
为YES
时程序继续运行,为NO
时,则抛出带有desc
描述的异常信息。NSAssert()
可以出现在程序的任何一个位置。
自定义一个宏
#define AC_Assert(condition) NSAssert(condition, ([NSString stringWithFormat:@"file name = %s ---> function name = %s at line: %d", __FILE__, __FUNCTION__, __LINE__]));
AC_Assert
这个宏的作用是当程序不满足condition
这个条件时,程序终止,并且输出不满足条件的类,以及是类的哪个函数和类中得行数