I'm trying to use a global error handling in my project as follow:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
NSSetUncaughtExceptionHandler { (exception) in
print(exception)
let myView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
let errorLabel :UILabel = UILabel(frame: CGRect(x: 10, y: (UIScreen.main.bounds.height/2) - 25 , width: UIScreen.main.bounds.width - 20 , height: 50))
errorLabel.text = "Exception"
myView.addSubview(errorLabel)
self.window?.addSubview(myView)
}
return true
}
But I get this error while coding:
A C function pointer cannot be formed from a closure that captures context.
I searched a lot but I couldn't find any answer. Is there anything else I need to do?
UPDATE:
I found out that the problem is because I'm declaring variables inside the block. How should I handle showing a view while exception happens?