This post covers four methods that are available to assist with debugging Objective-C, each providing information about the current application context. The first three of four are shown in the example below:
- (void)buttonPressed:(UIButton *)button
NSLog(@"Current selector: %@", NSStringFromSelector(_cmd));
NSLog(@"Object class: %@", NSStringFromClass([self class]));
NSLog(@"Filename: %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent]);
The above provides information about the selector that was called, in what class and the associated Objective-C source file (.m).
The fourth method available in Objective-C creates an array, where each entry is a string representing a value in the current stack trace. Here is how to print the stack trace:
NSLog(@"Stack trace: %@", [NSThread callStackSymbols]);
A stack trace can be quite helpful if you need to follow the flow of application logic to figure out where an error occurred.