美文网首页iOS 开发IT梦之队
iOS-宏定义NSLOG输出

iOS-宏定义NSLOG输出

作者: hyeeyh | 来源:发表于2016-09-21 17:09 被阅读2044次

    不废话 直接上代码:
    如果不想改变NSLOG输出就这样写

    //如果release状态就不执行NSLog函数
    #ifndef __OPTIMIZE__
    #define NSLog(...) NSLog(__VA_ARGS__)
    #else
    # define NSLog(...) {}
    #endif
    

    自定义:

    #ifdef DEBUG
    #define HYLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
    #else
    #define HYLog(...)
    #endif
    

    xcode 8真机测试 打印字符串

    #ifdef DEBUG
    #define HYString [NSString stringWithFormat:@"%s", __FILE__].lastPathComponent
    #define HY_Log(...)  printf("%s: %s 第%d行: %s\n\n",[hy_stringDate UTF8String], [HYString UTF8String] ,__LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String])
    
    #else
    #define HY_Log(...)
    #endif
    
    

    亲测有用。。。。。。。。。。

    相关文章

      网友评论

      • cz_Kim:[hy_stringDate UTF8String]这个代码可以看下么

      本文标题:iOS-宏定义NSLOG输出

      本文链接:https://www.haomeiwen.com/subject/hwpaettx.html