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?
-
2just put `NSLog("method called");` in the methods and it will do purpose – nsgulliver Mar 07 '13 at 22:39
-
1Put a breakpoint in the general vicinity of the reload method (or even in it) to get a stack trace in Xcode. – CodaFi Mar 07 '13 at 22:40
-
2Use the debugger and set a breakpoint on the method you want to check. When the code reaches that point, execution will stop. Look at the stack trace in the debugger to see who called it. – rmaddy Mar 07 '13 at 22:40
-
Ok I'll give these a shot @nsgulliver - great idea! Thanks all! – Brandon Mar 07 '13 at 22:44
-
The problem with using `NSLog` instead of breakpoints is that you can't see who called the method and you can't inspect variable values easily. Learn to use the debugger. It's a powerful and useful tool. – rmaddy Mar 07 '13 at 22:49
-
@Brandon, did you pick any of the solutions below? – Khaled Barazi Mar 12 '13 at 21:05
3 Answers
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.

- 8,681
- 6
- 42
- 62
-
-
-
@rmaddy, Agree 100%. That is why I prefaced my question with conditions. – Khaled Barazi Mar 07 '13 at 22:52
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.)

- 171,345
- 36
- 312
- 383
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:
- How to print out the method name and line number and conditionally disable NSLog?
- Do I need to disable NSLog before release Application?
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.