zoukankan      html  css  js  c++  java
  • ios中使用宏定义进行调试

    第一种,在控制台上输出日志信息:

    #ifdef DEBUG
    #define DLog(format,...) NSLog((@"DLog %s - [Line %d] %s
    
    " 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
    %s",fileName,line,functName];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:outString message:defugInfo delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        
    }
  • 相关阅读:
    UE4 UnLoadStreamLevel
    UE4 Xml读写
    UE4 保存为bitmap
    C++ 不定参数(转)
    C++ 默认参数(转载)
    Tuple初探
    遗传算法matlab实现
    蚁群算法matlab实现
    汉诺塔问题C++实现
    较优H圈matlab实现
  • 原文地址:https://www.cnblogs.com/xiaochaozi/p/3936143.html
Copyright © 2011-2022 走看看