1. Using Nsassert
It can be used as the return information of the custom bug, it is very convenient for debugging to know where the bug appears
Nsassert () is just a macro that is used for bugs in the development phase of the debugger, by passing conditional expressions for Nsassert () to determine if a bug is true, to satisfy a conditional return truth, to run a program, to throw an exception if a false value is returned, and to customize the description of the exception. Nsassert () is defined in this way:
#define NSASSERT (condition, desc)
condition is a conditional expression, with a value of Yes or No;desc as an exception, usually nsstring. When the program continues to run when Conditon is yes, exception information with desc description is thrown when no. Nsassert () can appear at any location in the program. Specific examples are as follows:
When generating an Lotteryentry object, the incoming nsdate cannot be determined by nil, adding Nsassert (). Object initialization source code is as follows:
-(ID) initwithentrydate: (NSDate *) thedate {
self = [super init];
if (self) {
Nsassert (thedate! = nil, @ "Argument must be Non-nil");
EntryDate = thedate;
Firstnumber = (int) random ()% 100 + 1;
Secondnumber = (int) random ()% 100 + 1;
}
return self;
}
Next, when you build the object, pass in a nsdate with a value of nil to see if the assertion is running.
Lotteryentry *nilentry = [[Lotteryentry alloc] initwithentrydate:nil];
The assertion effect is as follows:
2013-01-17 20:49:12.486 lottery[3951:303] * * * terminating app due to uncaught exception ' Nsinternalinconsistencyexception ', Reason: ' Argument must be Non-nil '
First throw Call stack:
(
0 corefoundation 0x00007fff90c590a6 __exceptionpreprocess + 198
1 LIBOBJC. A.dylib 0x00007fff8fd2a3f0 Objc_exception_throw + 43
2 corefoundation 0x00007fff90c58ee8 +[nsexception raise:format:arguments:] + 104
3 Foundation 0x00007fff88dae6a2-[nsassertionhandler handleFailureInMethod:object:file:lineNumb Er:description:] + 189
4 lottery 0x0000000100001929-[lotteryentry initwithentrydate:] + 249
5 Lottery 0x0000000100001794 main + 932
6 libdyld.dylib 0x00007fff8d83f7e1 start + 0
)
Libc++abi.dylib:terminate called throwing an exception
2. Using breakpoints
5.unrecognized selector Send to INSTANCD fast positioning
In the Debug menu, Breakpoints->create symbolic Breakpoint fill in the following method signature in symbolic
- -[nsobject (NSObject) Doesnotrecognizeselector:]
Once the setup is complete, you will be positioned to the specific code after encountering a similar error.
------The last debugging technique conditional breakpoint, which is just a normal breakpoint, and the program stops when a variable satisfies a certain condition. This debugging technique is useful when you want to capture a specific value of a variable in a loop, or something that doesn't happen often, without having to stop at each iteration to see it.
How do I turn on conditional variables? Just add a normal breakpoint, then right click on the breakpoint to select "Edit Breakpoint", then opened a breakpoint editor, you can set the breakpoint conditions (and some other breakpoint settings), and then choose "Done", this debugging technique is very simple
Debug Program bug-Chen Peng