How can I log names of each called class method in Objective-C? [duplicate]

匿名 (未验证) 提交于 2019-12-03 09:02:45

问题:

This question already has an answer here:

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.

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

Edit:

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:

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 

More info here, and here



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!