NSAssert NSCAssert NSParameterAssert, nsassertnscassert

Source: Internet
Author: User

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"]'






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.