Ios debugging skills

Source: Internet
Author: User

Ios debugging skills

I. BreakPoint (normal BreakPoint)

When the program runs to the breakpoint, It is paused.

The value of the corresponding parameter can be seen below the debugging process.

2. Condition BreakPoint)

Set the breakpoint attributes to make the breakpoint intelligent. Right-click the breakpoint attribute settings. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwPjxpbWcgYWx0PQ = "here write picture description" src = "http://www.bkjia.com/uploads/allimg/160326/0415191318-2.png" title = "\"/>

1. Condition parameters:The program is paused with a specific value. Indicates that the operation is paused when it reaches I = 2.

At this time, the console outputs the I = 0 and I = 1 values. When I = 2, the breakpoint effective program temporarily stops running. At this time, we will po out the I value and verify that the results are consistent.

2. lgnore parameter (int type ):Ignore n running times at the beginning of the program, and stop running at n + 1 times.

As shown in the figure, when 3rd numbers are output, the operation is stopped. At this time, the three numbers 0, 1, and 2 should be output. In this case, the value of po I Should Be I = 3. Verify.

3. Action parameters:Check the number of times a function is called and the specific function in which the function is executed. Set the Action parameter as follows. Make sure to select Automatically continue after evaluating actions.

3.1 Number of times the output function NSLog was called

View the Console

3.2. In which function is the output function NSLog executed (called)

View the console. The output function NSLog is called in viewDidload.

3. Exception BreakPoint)

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.

For a simple example, the following lines of code clearly cross the border.

After the program runs, when no global exception breakpoint is added, the program directly crash in the main function.

However, after you add an exception breakpoint, the specific code is located.

After an exception breakpoint is added, run the program again.

Iv. Symbolic BreakPoint)
A symbolic breakpoint can specify which class is interrupted when a specific method is executed. If there is no specific class and only the method name is written, the program is interrupted when the entire project runs to a method name.
The creation of a symbolic breakpoint is similar to that of an abnormal breakpoint.

Right-click to edit the symbol breakpoint: interrupt when _ loadRequest is specified in the ViewController class.

The effect is as follows:

When you have only the method name left in the symbolic breakpoint editing, the program will interrupt when the function name specified in the project is used.

5. botnets

Zombie objects: Objects in iOS that have been release but have not completely disappeared.
If you release a release object again, an exception occurs.
Since the use of ARC, exceptions have been greatly reduced due to object release, but occasionally occur. After the botnet mode is enabled, you can quickly locate the exception location. The method to enable this function is as follows: Product-> Scheme-> Edit Scheme.
Select Enable Zombie Objects.

Vi. lldb command
In Xcode, The llvm compiler is used. lldb is the debugger in llvm. We can use some simple commands for debugging. The po command is mentioned when we talk about breakpoints. This is one of the most common command lines, and the other is print.

7. Brute Force debugging

It should be said that NSLog printing information is a beginner's favorite debugging method and the simplest debugging method. View the program running path through the printed information. However, the output information is relatively small, NSLog is inefficient, and the loss performance is poor. When packaging and publishing an app, try to block this output function. A large number of people should define NSLog as a macro. Print it in debug, and do not print it in release. Then, in addition to this, the output function must be defined as a macro sea to continue optimization. Output details: Class Name, method name, detailed time, and row number.
#define NSLog(format, ...) do {   fprintf(stderr, "<%s : %d> %sn",   [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],   __LINE__, __func__);   (NSLog)((format), ##__VA_ARGS__);   fprintf(stderr, "-------n");   } while (0)  

8. Running time
Sometimes we want to know exactly the time for executing a code segment or loop, and then analyze the efficiency and other issues. What is the execution time required at this time.
Define two macros

#define TICK   NSDate *startTime = [NSDate date]#define TOCK   NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])

IX. Mobile screenshot
Maybe you may find this title very strange. Why are cell phone screenshots also placed in debugging skills? During daily development, we often use the mobile phone power key + Home key to take screenshots during the debugging phase of the real machine, and then use the communication software on the mobile phone to send the screenshots to other people, which is quite troublesome. X-code also provides a screen capture method.
When Debugging a real machine, choose debug> View Debugging> Take ScreenShot of IPhone. A mobile phone screen running on the mac desktop is generated. Note: You must set it once for each requirement.

10. UI debugging
Generally, old programmers like to use pure code to implement the UI. For new users, especially complicated UIS, It is a headache to take over such a project. X-code provides hierarchical relationships between views for debugging. When the program runs on a certain interface, you can click the following button.

In this way, you can easily view the hierarchical relationship between views in view debugging mode.

The tree hierarchy on the Left can be switched between viewing threads, queues, and UIS.

11. Memory Analyzer
Shortcut: commadn + shift + B
This is generally used to monitor memory leaks. It is a static tool that can analyze our programs and find out unused variables or some dead storage.

12. Profile
Components, almost every component can open a blog separately. Let's talk about it later.

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.