IOS development and debugging skills Summary (continuously updated)

Source: Internet
Author: User

IOS development and debugging skills Summary (continuously updated)

Debugging is a skill that must be learned for software development, and its importance is self-evident. Debugging skills can basically be migrated. That is to say, you have mastered many debugging skills on other platforms and many of them can also be used in iOS development. Debugging for different languages, ides, and platforms has the same sex and personality. Today, let's take a look at the debugging skills in iOS development. The language is currently OC, and IDE is of course a powerful Xcode. First, Xcode provides great convenience for debugging projects.

[1. Normal breakpoint]

Breakpoint is definitely the first choice for debugging programs and is also a basic skill. As the name suggests, the program is paused when it reaches the breakpoint. For example, if the breakpoint is hit on 11 lines, the program will stop on 11 lines (Note: The program runs only on the first 10 lines, and the 11th lines have not been executed yet !!!). As long as you click Next to the code line, you can add a breakpoint and click it again to make the breakpoint unavailable (disable, still exists, but does not work ). The shortcut for creating a breakpoint in a line is: command + \

.

 

.

You can see the parameter values below during the debugging process:

.

 

[2. Conditional breakpoint]

The above breakpoint is the most common. We can also configure the breakpoint attributes and set conditions to make the breakpoint more intelligent. Right-click the breakpoint to enter the edit dialog box:

.

 

I use a loop as the test code:

.

The code in the loop must be executed in a single step every time. This may not be what I want. I want to interrupt the program and debug it when I is 3. The writing conditions are as follows:

.

After the I = 3 condition is set, the program will be interrupted when the condition is set, instead of being interrupted every time it reaches the position. The output is as follows:

.

 

 

You can also set the Ignore parameter to Ignore the previous n breakpoint operations and interrupt the next n + 1.

.

The debugging output is as follows:

.

 

You can also view the number of times a function is called. Set the Action parameter as follows. Make sure to select Automatically continue after evaluating actions.

.

 

The output result is as follows:

.

[3. Exception breakpoint]

The breakpoint function is not limited to the above mentioned. The development of iOS knows that if the program crashes due to an exception, the code will directly go to the main function of main. m. Why can't I go to the abnormal code ??? The exception breakpoint solves this problem for us, and the program will terminate the code in the line where the exception occurs. The following is an example of creating an exception breakpoint:

.

The creation is completed as follows. If you encounter an exception crash, try to use the exception breakpoint.

.

 

[4. Symbolic Breakpoint]

The creation of a symbolic breakpoint is also the same as that of an exception breakpoint. Generally, a symbolic breakpoint can be interrupted when you specify the [class name method name.

.

 

The configuration symbol breakpoint is as follows: You can interrupt the execution when the viewDidLoad method of the ViewController class is executed.

.

 

If your Symbol only writes a function name, the execution will be interrupted when the function name appears. As follows, it will be interrupted when running to doAnimation. Is it very powerful?

.

 

[5. Analyze analyzer]

Analyze analyzer is a static tool that can Analyze our programs and find out unused variables or some dead storage. Execute Analyze as follows: Product --> Analyze. The following blue mark is the result of static analysis.

.

 

.

 

Of course, we can set Analyze while compiling the program, and set the following options to Yes.

.

[6. Profile checker]

This tool is really too NB-intensive. I can't finish it in just a few words. I will post a picture to show you how to use it in my blog. Also open in Product --> Profile.

.

[7. Zombie objects]

In iOS, the objects that have been release but have not completely disappeared are called Zombie objects. If you release the objects that have been release again, an exception will occur. Although the exception caused by object release has been greatly reduced since the use of ARC, it occasionally appears. After the botnet mode is enabled, you can quickly locate the exception location. To Enable this function, choose Product> Scheme> Edit Scheme. Select Enable Zombie Objects.

.

[8. lldb command]

The llvm compiler is used in Xcode, which is regarded as the best C, C ++, OC, and Swift compiler. Lldb is the debugger in llvm. We can use some simple commands for debugging. I still use the above loop code as the test code.

.

 

In breakpoint debugging, use the po and print commands to print the variable information on the Console:

.

[9. NSLog printing]

It should be said that NSLog printing information is a beginner's favorite debugging method and the simplest debugging method. You can view the program running path through the printed information. However, the output information is relatively small, and NSLog is inefficient. Some people use macros for some optimization. The Code is as follows: the class name, method name, detailed time, and row number can be printed.

#import "ViewController.h"#define NSLog(format, ...) do { \fprintf(stderr, "

Related Article

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.