IOS debugging skills-compiler predefined macros

Source: Internet
Author: User

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!

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.