问题
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