Xcode debugger sometimes doesn't display variable values?

后端 未结 19 2098
醉话见心
醉话见心 2020-12-14 13:54

This happens to me pretty often. For example, right now I have the debugger stopped at a breakpoint in a method . . . and it isn\'t displaying any variable values at all.

相关标签:
19条回答
  • 2020-12-14 14:42

    One possible reason for the debugger displaying seemingly wrong values is that the variable type is of Any?.

    E.g.

    var a: Any? = 12
    var b: Int? = a as? Int // b=13483920750
    var c: Int = a as? Int ?? 0 // c=1
    

    In the example above, b holds the correct value of 1 even though it is not displayed as such.

    0 讨论(0)
  • 2020-12-14 14:43

    A possible solution is to set the Optimization Level for your current target Debug scheme to none.

    Project -> Target -> Build settings -> Optimization level -> Debug (or whatever fits your project) -> None

    Source:

    https://stackoverflow.com/a/14948486/3590753

    0 讨论(0)
  • 2020-12-14 14:46

    If your breakpoint has "automatically continue after evaluating options" set, then it won't write to the variable view - FYI

    0 讨论(0)
  • 2020-12-14 14:47

    temporary solution when it happpen to me : right click on the property jump to definition (u can do it manually and scroll to the @synthesize in the top of the file)

    now, if the line is like this :

    @synthesize myObject = _myObject ;

    set the mouse cursor on the "_myObjects". that what worked for me..when i have problems.

    0 讨论(0)
  • 2020-12-14 14:48

    My issue was that I had address sanitizer enabled. Disabling sanitizer resolved my issue in XCode 8.2.1

    0 讨论(0)
  • 2020-12-14 14:51

    If you are using the @property feature of Objective-C 2.0 the debugger does not display those variables unless they are backed by explicit ivars in your Class interface. This is slated to be fixed in Xcode 4 as I understand it.

    0 讨论(0)
提交回复
热议问题