如何找出谁叫方法?

示例:当我的方法-fooBar被调用时,我希望它在控制台中登录哪个其他类的另一个方法调用它。


现在,我只知道如何使用以下命令记录fooBar本身及其类的方法名称:


_cmd


[self class]

这可能找出来吗?


呼如林
浏览 419回答 3
3回答

LEATH

用户以下方法&nbsp;通行证指数要显示方法和传递-1,如果你想显示方法的全栈+(void) methodAtIndex:(int)index{&nbsp; &nbsp; void* callstack[128];&nbsp; &nbsp; int frames = backtrace(callstack, 128);&nbsp; &nbsp; char** strs = backtrace_symbols(callstack, frames);&nbsp; &nbsp; if (index == -1) {&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i < frames; ++i) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("%s\n", strs[i]);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; else {&nbsp; &nbsp; &nbsp; &nbsp; if (index < frames) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("%s\n", strs[index]);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; free(strs);}
打开App,查看更多内容
随时随地看视频慕课网APP