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