Detecting if iOS app is run in debugger

前端 未结 8 1811
北恋
北恋 2020-11-27 13:45

I set up my application to either send debugging output to console or a log file. Now, I\'d like to decide with in the code whether

  • it is run in the debugger
8条回答
  •  离开以前
    2020-11-27 14:02

    Why not using conditional compilation block in Swift?

         #if DEBUG
            // Do something.
         #endif
    

    Any objection?

    You can define if you want a runtime constant

    #if DEBUG
    public let IS_RUNNING_IN_DEBUGGER: Bool = true
    #else
    public let IS_RUNNING_IN_DEBUGGER: Bool = false
    #endif
    

    The same approach can be used in Objc & more.

提交回复
热议问题