NSAssert NSCAssert NSParameterAssert, nsassertnscassert
@ Here we will introduce several systems to facilitate program debugging and locate the wrong macro.
When writing a program, you can add this code to areas that are not at ease or are prone to errors.
# Define NSAssert (condition, desc ,...) # define NSCAssert (condition, desc ,...) the first parameter is a condition judgment. If it is false, an exception is thrown, showing the information described by the second parameter (defined as an error prompt that you can see clearly ). For example, NSString * test = @ "HMT"; NSAssert ([test isEqualToString: @ "TMH"], @ "your name is error"); NSCAssert ([test isEqualToString: @ "TMH"], @ "your name is error"); 1. running in debug mode will terminate the program and throw the following exception: 18:26:02. 008 DemoTest [42915: 60b] *** Terminating app due to uncaught exception 'nsinternalinconsistencyexception', reason: 'Your name is error' 2. run in release mode. If the program is not terminated, no exception is thrown. @ Be careful when using NSAssert. You can see a self in its definition. You may find that you do not have the strong reference of self in your block, but loop references still appear. Check whether you have used NSAssert. If the macro is expanded and held self, the reference may not be released. With NSCassert, there will be no such problem. Because it defines the handleFailureInFunction used, there is no self reference. # Define NSParameterAssert (condition) when the conditions set in the corresponding position are not met, use NSParameterAssert to make the program crash to the corresponding position: 18:26:43. 524 DemoTest [42982: 60b] *** Terminating app due to uncaught exception 'nsinternalinconsistencyexception', reason: 'invalid parameter not satisfying: [test isEqualToString: @ "TMH"]'