IOS debugging skills-compiler predefined macros
As we all know, Objective-C is a superset of C language and must retain some features of C language. Today, we will use the predefined macros of the compiler to output some information to debug the program.
These macros include:
(1) _ FUNCTION _: // obtain the current method name;
(2) _ func _: // obtain the current method name;
(3) _ PRETTY_FUNCTION _: // obtain the current method name;
(4) _ LINE _: // obtain the current row;
(5) _ FILE _: // obtain the absolute path of the FILE;
(6) _ DATE _: // obtain the current DATE;
(7) _ TIME _: // obtain the current hour, minute, and second;
(8) _ TIMESTAMP _: // obtain the current TIMESTAMP;
The sample code is as follows:
# Import "SecondViewController. h "@ interface SecondViewController () @ end @ implementation SecondViewController-(void) viewDidLoad {[super viewDidLoad]; // obtain the class name (File Name ); NSString * className = NSStringFromClass ([self class]); NSLog (@ "class Name -------- % @", className); // get the current method name; NSLog (@ "% s" ,__ FUNCTION _); // obtain the current method name; NSLog (@ "% s" ,__ func __); // obtain the current method name; NSLog (@ "% s" ,__ PRETTY_FUNCTION _); // obtain the current row; NSLog (@ "% d ", __line _); // obtain the absolute path of the FILE; NSLog (@ "% s" ,__ FILE _); // obtain the current date; NSLog (@ "% s" ,__ DATE _); // obtain the current hour, minute, and second; NSLog (@ "% s" ,__ TIME __); // obtain the current TIMESTAMP; NSLog (@ "% s" ,__ TIMESTAMP _);} @ end
The output result is as follows:
.
To sum up, you can use these predefined macros to quickly print logs at the desired location, so that we can debug the program. This is also a little bit of coding skills!