In Objective-C, you can print the call stack by doing the following:
NSLog(@"%@", [NSThread callStackSymbols]);
How do you do this in Swift without using Foundation class?
In Objective-C, you can print the call stack by doing the following: NSLog(@"%@", [NSThread callStackSymbols]);
a call stack is a stack data structure that stores information about the active subroutines of a computer program. A stack trace is a report of the active stack frames at a certain point in time during the execution of a program.
As Jacobson says, use the following:
print(NSThread.callStackSymbols())
print(Thread.callStackSymbols)
That's Swift code. It's using a Foundation method, but so does 90%+ of what you do on iOS.
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With