• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

在iPhone上自定义NSLog功能

用户头像
it1352
帮助1

问题说明

我知道可以对Objective C中的选择器和方法进行方法混淆.是否可以将诸如NSLog之类的函数混淆到我们的自定义函数中.我想在自定义函数中与NSLog一起添加一些额外的功能.

I know that it's possible to do method swizzling for Selectors and Methods in Objective C. Is it possible to swizzle functions like NSLog to our custom function. I wanted to add some extra functionality along with NSLog in the custom function.

我最终使用了另一个函数,该函数将在内部调用NSLog.

I finally ended up using another function which will call NSLog internally.

#define NSLog(...) CustomLogger(__VA_ARGS__);

void CustomLogger(NSString *format, ...) {
    va_list argumentList;
    va_start(argumentList, format); 
    NSMutableString * message = [[NSMutableString alloc] initWithFormat:format 
                                                arguments:argumentList];


    [message appendString:@"Our Logger!"];
    NSLogv(message, argumentList);

    va_end(argumentList);
    [message release];
}

正确答案

#1

似乎可行,但完全不受支持,并且可以随时更改.

It seems possible, but entirely unsupported, and can change at any time.

请参见如何操作我将所有错误(包括未捕获的异常,NSLog调用和其他日志)重定向到Mac OS X上的日志文件吗?

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfggai
系列文章
更多 icon
同类精品
更多 icon
继续加载