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

在 Objective-C 记录每个被调用的类方法的名称?

用户头像
it1352
帮助1

问题说明

当我想查看对象方法调用的顺序时,我必须像这样记录我实现的每个方法.

When I want to see the order of the object method calls, I have to put logs each method I implemented like this.

- (void)updateTime:(float)time
{
  NSLog(@"%s", __PRETTY_FUNCTION__);

所以我不得不把这段代码放在类的每个方法中,每次调试一个类的时候插入和删除这么多日志函数调用很无聊.

Hence I have to put this code in every method on the class, and it's very boring to insert and delete so many log function calls every time I am debugging a class.

那么如何在每个方法调用的类中触发 NSLog(@"%s", __PRETTY_FUNCTION__);?

So how can I trigger NSLog(@"%s", __PRETTY_FUNCTION__); in a class on each method call?

我最终得到了这段代码.并且在其他任何地方都没有得到答复.

I ended up with this code. And was not answered anywhere else.

- (BOOL)respondsToSelector:(SEL)aSelector {
    if(aSelector){
        NSLog(@"%@", NSStringFromSelector(aSelector));
    }
    return [super respondsToSelector:aSelector];
}

正确答案

#1

您可以使用 NSObjCMessageLoggingEnabled=YES 运行您的可执行文件.您可以在 Xcode Schemes 中的 Run 下的 Argument Variables 下进行设置.

You can run your executable with NSObjCMessageLoggingEnabled=YES. You can set this in Xcode Schemes, under Argument Variables under Run.

你最终会得到类似的输出

You end up with output like

      NSObject NSObject initialize
      NSNotificationCenter NSObject initialize
      NSNotificationCenter NSNotificationCenter defaultCenter

更多信息这里和这里

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

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