Improve log output of Objective-C

Source: Internet
Author: User

The C Preprocessor provides some standard macros that can provide information about the current file, row number, or function. In addition, Objective-C has the _ cmd implicit parameter, which can provide the selector of the current function and convert the selector and class to a string. You can provide the context information in the NSLog statement during debugging or error handling. The following is an example of printing the current method and row number. NSMutableArray * someObject = [NSMutableArray array]; NSLog (@ "% s: % d someObject = % @", _ func __, _ LINE __, someObject ); [someObject addObject: @ "foo"]; NSLog (@ "% s: % d someObject = % @", _ func __, _ LINE __, someObject ); the following are very common macros and expressions that are useful in log statements. Preprocessing macros used for log output in C/C ++/Objective-C. macro Format Specifier Description _ func _ % s before the current function _ LINE _ % d LINE number in the source code FILE _ % s full path of the source code FILE _ PRETTY_FUNCTION _ _ % s and _ func _ are similar, however, the C ++ Code contains more information. expression Format Specifier DescriptionNSStringFromSelector (_ cmd) % @ NSStringFromClass ([self class]) for log output in Objective-C % @ name of the current object class [[NSString stringwithuf8string :__ FILE _] lastPathComponent] % @ name of the source code FILE [NSThread CallStackSymbols] % @ the scale string array of the current stack information. It is only used for debugging and does not need to be presented to end users or used as any logic in the code.

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.