How can I determine the “caller” of my method in Objective-C? [duplicate]

六眼飞鱼酱① 提交于 2019-12-20 01:03:49

问题


So I have a rather complex application that I've, perhaps naively, agreed to "debug". Upon entering into a certain method, I'd like to print out as much info about who called the method, from which class, method, etc. it was called from. Any suggestions would be very much appreciated!!


回答1:


Just add in your method:

NSLog(@"Show stack trace: %@", [NSThread callStackSymbols]);



回答2:


For debugging you could use a debugger :) put a breakpoint in the method and view the backtrace.

You could also scatter NSLog statements with relevant information in methods.



来源:https://stackoverflow.com/questions/1970354/how-can-i-determine-the-caller-of-my-method-in-objective-c

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