XCODE debugging skills collection

Source: Internet
Author: User

Note: errors and exceptions are inevitable during code writing. This shows the importance of debugging. The following is a summary, I usually use some debugging skills and summarize the skills used by other netizens on the network. (New debugging skills will be available in the future, and I will update them together)

1. Use a zombie variable (NSZombieEnabled)

2. Override the respondsToSelector method of the object.

It is difficult to find the cause of the EXC_BAD_ACCESS bug During iphone development.

First, let's talk about the EXC_BAD_ACCESS error. It can be said that the 90% error is caused by performing the release operation on a released object, or operating an object in the sequence modified in the loop code. Although the NSZombieEnabled variable can help you locate the problem, sometimes, even if you still cannot locate the problem by setting the NSZombieEnabled variable, you can try to override the respondsToSelector method of the object, the last object accessed before EXEC_BAD_ACCESS is displayed. The specific steps are as follows:
A. Add-D _ FOR_DEBUG _ to each class and other c flags (remember to add this flag only under Debug Configuration ). In this way, when your program crashes, the Xcode console will accurately record the method of the last running object. In the implementation file (. m,. mm), add the following code:
[Cpp]
-(BOOL) respondsToSelector: (SEL) aSelector {
Printf ("SELECTOR: % s \ n", [NSStringFromSelector (aSelector) UTF8String]);
Return [super respondsToSelector: aSelector];
}

B. Add-D _ FOR_DEBUG _ to other c flags (remember to add this flag only under Debug Configuration ). In this way, when your program crashes, the Xcode console will accurately record the method of the last running object.

3. Enable XCode to provide sufficient information.

Find Arguments in Edit-> Scheme and add it to Environment Variables.
Set the following two values to YES.
NSAID utoreleasefreedobjectcheckenabled
NSDebugEnabled
This method is very useful. We recommend that you add this setting when creating a project.

4. Set a global exception breakpoint

When the program throws an exception, it is often necessary to locate the exception
Enter the shortcut key cmd + 6 to enter the BreakPoint window, click the "+" button in the lower left corner, and select the "Add Exception BreakPoint" option in the pop-up box, as shown in:

Use the default settings and click "done" to set the global exception breakpoint.

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.