In Objective-C, Whenever an application crashes, I can get stack trace to see where is the last method that causes the error by using this code in AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(&myExceptionHandler);
return YES;
}
void myExceptionHandler(NSException *exception)
{
NSArray *stack = [exception callStackSymbols];
NSLog(@"Stack trace: %@", stack);
NSLog(@"MyExceptionHandler");
}
and it will print the stack trace log to console which I can use to debug the cause of the problem instead of ending up at main.m
with no information
So how can I do this in Swift?