Reputation: 2171
I have a view controller that keeps reloading over and over again. I would like to be able to see which methods are being called so that I can see the one that keeps firing the reload. I know I can see what was called if an error occurs and the app crashes. However, in this case there is no crash. Is there a way to monitor all of the methods being called throughout the app?
Upvotes: 3
Views: 4146
Reputation: 3065
I use this macro:
#define DEBUG 1
#if DEBUG
# define NLog(fmt, ...) printf("%s\n", [[NSString stringWithFormat:@"%s:%d %@", __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:fmt, ##__VA_ARGS__]] UTF8String])
#else
# define NLog(...)
#endif
Then I include my Macros.h in my Application_Prefix.pch file, so that it's available everywhere. Before I ship, I set DEBUG to 0 so that all NLogs disappear.
So now, instead of using NSLog, I use NLog. The output looks something like this:
-[ApplicationDelegate applicationDidBecomeActive:]:86 applicationDidBecomeActive called!
This solution was based on these earlier posts:
You can just place the NLog calls in several places, to see which functions are called right before your view controller reloads. If you need to know the exact function that triggered the reload, your best bet would be to place a breakpoint and examine the call stack, as others have mentioned.
Upvotes: 1
Reputation: 8741
If you are new to XCode and Objective C and looking for something lightweight and you do not have a large code/ many methods, I would put:
NSLog(@"%s",__PRETTY_FUNCTION__);
in every method.
Upvotes: 3
Reputation: 179402
Use Instruments. Start your code in a profiling mode and select the CPU time instrument. As the app runs, Instruments will gather information about every call stack at regular intervals, which will allow you to see what calls what. (Use the "Invert Call Tree" option to see callers of a given function.)
Upvotes: 3