Possible Duplicate:
Intercept method call in Objective-C
How to log all methods used in iOS app
For example, a UIViewController object in iOS receives many messages before its view is shown to a user:
viewWillAppearviewWillLayoutSubviewsviewDidLayoutSubviewsviewDidAppear- …
because the framework’s source code is not viewable, we have to rely on books or blogs, or is there a way to print out or monitor all the messages sent to this object by (1) Objective-C, or (2) by any tool?
Rather than my comment, the best approach that I used (and still use) is calling:
When I need to start logging all messages and then:
Don’t forget to add
#import <objc/runtime.h>.When I don’t need it anymore. The annoying thing is that the log is created under
/tmp/msgSends-and this means that you have to open the terminal and usetailto see it in a readable way.What is printed is something like this:
Note: It has been a while since I used this approach for the last time and it looks like this approach doesn’t log private methods subclassed. So, if you have a
DummyClasswith-(void)_dummyMethodas private and then aDummySubClasswith a-(void)_dummyMethodimplementation, the message will not be logged.For iOS, this works only on Simulator.