5 Xcode Development Debugging Tips

Source: Internet
Author: User

1.Enable Nszombie Objects (Turn on Zombie object)

The Enable Nszombie objects is probably the most useful debugging technique in the entire Xcode development environment. This technique is very very easy to trace to the problem of repeated release. This technique prints the class that indicates the duplicate release and the memory address of the class in a very concise manner.

How do I turn on zombie objects? First Open "Edit Scheme" (or via Hotkey?<), then select the Diagnostics tab and tick the Enable Nszombie objects option.

Now we can turn off arc to test the problem of repeated releases, anomalies, and more easily generated crashs, but even if arc is turned on, repeated releases and memory-related CRASHS often occur. Now suppose we make some mistakes that lead to repeated releases to see what's going to happen.

[OBJC]View Plaincopy
    1. uiview* view = [[[UIView alloc] init] autorelease];
    2. //...
    3. Do something with view...clearly forgetting the It has been autoreleased.
    4. //
    5. [view release];

Now that the code is running, a duplicate release will occur, and the program will crash in the main function, as follows:

Enable Nszombie objects will make the debugger look like this:

This example looks very small, but it is very useful for a large project to print information through the Enable Nszombie objects.

2. Add Global Breakpoint (Global Breakpoint) for all exceptions

When your app is abnormal or crashes, one of the things that Xcode likes to do is jump directly to the main function, just like the first one in the debugging technique. It would be nice if the exception or crash could stay where the anomaly or crash occurred. Fortunately, there is a way to do that. Xcode has a nice feature called an exception breakpoint that allows us to place a breakpoint where the exception occurs when the exception occurs. You can specify a specific exception or you can specify all exceptions.

How do I turn on an abnormal breakpoint? The project switches to the Exception browser window, click on the "Add Breakpoint" button on the left, and select "Add Exception Breakpoint" to ensure that all exceptions can be captured.

Now that the exception occurs, the debugger does not jump directly to the main function, but instead stops at the place where the exception occurred.

This breakpoint gives us a very good starting point to debug the exception, we do not have to go through the generation to buy to find where the anomaly occurred.

3.Static Analyzer (Static analysis)

Static Analyzer is a very good tool to find compiler warnings that do not prompt problems and errors in some personal internal error leaks and dead storage (which are not used by assigned value variables). This approach can greatly improve memory usage and performance, as well as improve the overall stability and code quality of your application.

How do I open the static Analyzer? Open the Xcide Product menu and select the Analyzer option (or use the hotkey?). Shift B). As you can see below, Static Analyzer captures possible problems in any application and then displays them with a blue warning.

We can also set up our app to automatically turn on Static Analyzer when we compile the app, open the project projects file, and set "Run Static Analyzer" to Yes, such as:

4.Condational Breakpoints (conditional breakpoint)

The last debugging technique is a conditional breakpoint, which is just a normal breakpoint, and the program stops when the 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.

5.unrecognized selector Send to INSTANCD fast positioning

Breakpoints->create symbolic Breakpoint in the Debug menu

In symbolic, fill in the following method signature

[OBJC]View Plaincopy
    1. -[nsobject (NSObject) Doesnotrecognizeselector:]

Once the setup is complete, you will be positioned to the specific code after encountering a similar error.

(EXT) 5 Xcode development Debugging Tips

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.