Debugging with macro definitions in iOS

Source: Internet
Author: User

First, output the log information on the console:

#ifdef DEBUG #define DLog (Format,...) NSLog (@ "DLog%s-[line%d]%s\n\n" format), __pretty_function__,__line__, __function__,# #__VA_ARGS__)#else #define DLog (format,...) does {} while (0)#endif

Let the NSLog function only when the debug build. Add this feature to a header file that can be accessed globally. This allows you to use log as you like, and does not include the log-related code when you are production.

Second, define the Alertview control output:

#define Showalert (format, ...) Myshowalert (__line__, (char *) __function__, format, # #__VA_ARGS__)
voidMyshowalert (intLineChar*functname,IDformatstring,...)    {va_list arglist; if(!formatstring) {        return;    } va_start (arglist, formatstring); IDOutstring =[[NSString alloc] initwithformat:formatstring arguments:arglist];        Va_end (arglist); NSString*filename =[[NSString stringwithcstring:__file__ encoding:nsutf8stringencoding] lastpathcomponent]; NSString*defuginfo = [NSString stringWithFormat:@"file=%@ line=%d\n%s", Filename,line,functname]; Uialertview*alert = [[Uialertview alloc] initwithtitle:outstring message:defuginfoDelegate: Nil Cancelbuttontitle:@"OK"Otherbuttontitles:nil, nil];    [Alert show]; }

Debugging with macro definitions in iOS

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.