在 Objective-C 记录每个被调用的类方法的名称?
问题说明
当我想查看对象方法调用的顺序时,我必须像这样记录我实现的每个方法.
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];
}
正确答案
您可以使用 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
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22