How to use NSSetUncaughtExceptionHandler to show exception message on UIView in Swift

后端 未结 2 908
天涯浪人
天涯浪人 2021-01-23 11:46

I use Martin R\'s answer to print the NSSetUncaughtExceptionHandler in Swift.

How should I use NSSetUncaughtExceptionHandler in Swift

  func exceptionHan         


        
2条回答
  •  既然无缘
    2021-01-23 12:17

    NSSetUncaughtExceptionHandler takes a C function pointer, and C function bodies are fixed at compile-time. C function pointers get bridged into 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; i.e. top-level Swift functions, or anonymous function which don't capture any variables.

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

提交回复
热议问题