Here is a simple example, for everyone's understanding, the use of single-step debugging
The one-step debugging in Xcode is very useful, and we can use it to correct the program.
It's easy for us to find the root of the error, a skill that programmers must have
To solve the problem we need to set a breakpoint, and then one step to debug, encountered the method body, we can jump into the
Method body, so that we find the change of each variable value, and the concrete steps of the function implementation
A clearer understanding of the steps we have written to execute the program
First I put the simple code out, although simple, but we must master the power of debugging
Defines a Calcultor class
There are two member variables
There are two ways of
Main.m
#import <Foundation/Foundation.h> #import "Calcultor.h" int main (int argc, const char * argv[]) { Calcultor * cal = [[Calcultor alloc]init]; [Cal Seta:10]; [Cal Setb:20]; NSLog (@ "%d", [cal Add]); NSLog (@ "%d", [Cal Sub:10 Andb1:10]); return 0;}
Calcultor.h
#import <Foundation/Foundation.h> @interface calcultor:nsobject{ int _a; int _b;} @property int A; @property int b;-(int) add;-(int) sub: (int) A1 ANDB1: (int) B1; @end
Calcultor.m
#import "Calcultor.h" @implementation calcultor-(int) add{ return _a + _b; NSLog (@ "A+b");} -(int) sub: (int) A1 ANDB1: (int) B1; { //_a = A1; _b = B1; return _a + _b;} @end
First step: Set breakpoints
Step two: Command + R starts execution
Into the debug state, we can see there is a debug window at the bottom left, there is no execution, so the initial value of a B is 0, here is called the parent class constructor method to assign a value to the member variable
The third step is to perform one-step debugging as follows:
Fourth step: Enter inside the function body
Fifth step: Enter the inside of the Add function body
Sixth step: Click Next to jump out of function body back to main function
Share with us useful dry foods and learn together
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Implementation of IOS with parametric function body and non-parametric function body and Xcode single step debugging