首页 > 代码库 > ios中使用宏定义进行调试
ios中使用宏定义进行调试
第一种,在控制台上输出日志信息:
#ifdef DEBUG#define DLog(format,...) NSLog((@"DLog %s - [Line %d] %s\n\n" format), __PRETTY_FUNCTION__,__LINE__, __FUNCTION__,##__VA_ARGS__)#else#define DLog(format,...) do {} while(0)#endif
让NSLog只在debug build的时候起作用。将这个功能添加到全局都能访问得到的头文件中。这样你就可以尽情的使用log了,并且当进行production时,不会包含log相关代码。
第二种,定义AlertView控制输出:
#define ShowAlert(format, ...) myShowAlert(__LINE__, (char *)__FUNCTION__, format, ##__VA_ARGS__)
void myShowAlert(int line, char *functName, id formatstring,...){ va_list arglist; if (!formatstring) { return; } va_start(arglist, formatstring); id outString = [[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:defugInfo delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; }
ios中使用宏定义进行调试
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。