How to print call stack in Swift? How to print call stack in Swift? swift swift

How to print call stack in Swift?


As Jacobson says, use the following:

Swift 2:

print(NSThread.callStackSymbols())

Swift 3 / Swift 4:

print(Thread.callStackSymbols)

That's Swift code. It's using a Foundation method, but so does 90%+ of what you do on iOS.

EDIT:

Note that the formatting looks better if you use:

Thread.callStackSymbols.forEach{print($0)}

From the debugger command line you can type

e Thread.callStackSymbols.forEach{print($0)}


For Swift 3 use:

print(Thread.callStackSymbols)

or for better formatting

for symbol: String in Thread.callStackSymbols {    print(symbol)}


This improves the output a little.

for symbol: String in NSThread.callStackSymbols() {    NSLog("%@", symbol)}