打印当前的函数名可以使用__PRETTY_FUNCTION__宏,或者封装一下:
- #define NSSTRING_PRETTY_FUNCTION [NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSASCIIStringEncoding]
打印:
- NSLog("Function Name:%@",NSSTRING_PRETTY_FUNCTION);
打印调用堆栈可以借助于: callStackSymbols
- NSArray *syms = [NSThread callStackSymbols];
- if ([syms count] > 1) {
- NSLog(@"<%@ %p> %@ - caller: %@ ", [self class], self, NSStringFromSelector(_cmd),[syms objectAtIndex:1]);
- } else {
- NSLog(@"<%@ %p> %@", [self class], self, NSStringFromSelector(_cmd));
- }