How to print call stack in Swift?

后端 未结 5 1635
野性不改
野性不改 2020-12-23 11:19

In Objective-C, you can print the call stack by doing the following:

NSLog(@\"%@\", [NSThread callStackSymbols]);

How do you do this in Swi

5条回答
  •  独厮守ぢ
    2020-12-23 12:08

    I needed to write the callstack to a log file so I tweaked it like so.

    var ErrorStack = String()
    Thread.callStackSymbols.forEach {
        print($0)
        ErrorStack = "\(ErrorStack)\n" + $0
    }
    

提交回复
热议问题