How to use NSSetUncaughtExceptionHandler to display exception message from UIView in Swift

I am using Martin R's answer to print NSSetUncaughtExceptionHandler in Swift.

How to use NSSetUncaughtExceptionHandler in Swift

func exceptionHandler(exception : NSException) { let alert = UIAlertController(title: "Exception", message: "\(exception)", preferredStyle: .Alert) self.presentViewController(alert, animated: true, completion: nil) print(exception) print(exception.callStackSymbols) } 

But how can I display a message in a UIView. Like this

enter image description here

Since I received an error message in the compiler, I said that "the CC function pointer can only be formed from a reference to" func "or literal closure.

Handling unhandled exceptions and cues written by Matt Gallagher at Cocoa with love.

enter image description here

+1
ios exception swift uiview
Oct 05 '15 at 15:47
source share
2 answers

NSSetUncaughtExceptionHandler accepts a C function pointer, and C function bodies are fixed at compile time. Function C pointers are connected in Swift 2 as @convention(c) function types, and, like in C, you can only pass a function whose body can be fixed at compile time; that is, top-level Swift functions or anonymous functions that do not commit any variables.

Your anonymous function captures self from the scope, so it cannot be used as a C. function. You should try to access the controller or do what you need to do in another way, using only global variables or classes.

0
Oct 06 '15 at 8:03
source share

using NSSetUncaughtExceptionHandler

 NSSetUncaughtExceptionHandler { exception in print("EXception Details Are \n\nExceptionName--> \(exception.name) \nReason -->\(exception.reason!)\n\(exception.description)") print(exception.callStackSymbols) } 
-one
Dec 22 '15 at 12:29
source share



All Articles