Ios 如何在Xcode中打印代码的所有方法?

Ios 如何在Xcode中打印代码的所有方法?,ios,objective-c,xcode,Ios,Objective C,Xcode,如何按顺序打印文件中的所有方法?只需打印一次 我想打印所有执行的方法。给定NSLog(@“%s”,\uuu func\uuu),只打印方法名称。我想得到这样的日志: 2018-01-11 15:31:58.592319+0800 Test[9574:769688] -[ViewController viewDidLoad] 2018-01-11 15:31:58.597790+0800 Test[9574:769688] -[ViewController prepareTableView] 20

如何按顺序打印文件中的所有方法?只需打印一次

我想打印所有执行的方法。给定
NSLog(@“%s”,\uuu func\uuu)
,只打印方法名称。我想得到这样的日志:

2018-01-11 15:31:58.592319+0800 Test[9574:769688] -[ViewController viewDidLoad]
2018-01-11 15:31:58.597790+0800 Test[9574:769688] -[ViewController prepareTableView]
2018-01-11 15:31:58.599040+0800 Test[9574:769688] -[ViewController viewWillAppear:]
2018-01-11 15:31:58.805699+0800 Test[9574:769688] -[ViewController viewWillLayoutSubviews]
2018-01-11 15:31:58.805953+0800 Test[9574:769688] -[ViewController viewDidLayoutSubviews]
2018-01-11 15:31:58.806717+0800 Test[9574:769688] -[ReloadTest reloadData]
2018-01-11 15:31:58.808404+0800 Test[9574:769688] -[ReloadTest layoutSubviews]
2018-01-11 15:31:58.808745+0800 Test[9574:769688] -[ViewController viewWillLayoutSubviews]
2018-01-11 15:31:58.808970+0800 Test[9574:769688] -[ViewController viewDidLayoutSubviews]
2018-01-11 15:31:58.809384+0800 Test[9574:769688] -[ReloadTest layoutSubviews]
2018-01-11 15:31:58.814083+0800 Test[9574:769688] -[ViewController viewDidAppear:]

我不确定这是否是您的意思(这将按调用顺序记录调用的方法,而不是类中的所有方法):

使用这样的类:

@interface MyClass : NSObject
- (void)step0;
- (void)step1:(int)x;
- (void)step2:(int)x;
@end

@implementation MyClass
- (instancetype)init {
    if (self = [super init]) {
        [self step0];
    }
    return self;
}
- (void)step0 {
    [self step1:1];
}
- (void)step1:(int)x {
    [self step2:(x + 1)];
}
- (void)step2:(int)x {
    //Here's how we got here:
    [Backtracer logBacktrace];
}
@end
这样称呼这个人为的例子:

(void)[MyClass new];
结果:

... backtrace:

-[MyClass init]
-[MyClass step0]
-[MyClass step1:]
-[MyClass step2:]

可能的重复:可能的重复:谢谢。如何按顺序打印文件中的所有方法?只需打印一次。请尝试使用
\uu PRETTY\u FUNCTION\uuuu
而不是
\uuu func\uuu
非常感谢。它在调试时很有用。
... backtrace:

-[MyClass init]
-[MyClass step0]
-[MyClass step1:]
-[MyClass step2:]