How do you watch or evaluate an expression in xcode like visual studio's immediate window?

前端 未结 6 909
滥情空心
滥情空心 2021-02-05 06:08

In MS visual studio we just right click add watch.

How does one do this in Xcode?

6条回答
  •  旧巷少年郎
    2021-02-05 06:43

    If you want to know when the variable changes, use a "watch":

    1. Set a breakpoint somewhere in the class in question;
    2. Run the app in the debugger and let it stop at your breakpoint; and
    3. Go to the "Variables" view in the left side of the bottom "Debug" panel and right click on the property in question and choose "Watch".

    For example, here, I've stopped at a breakpoint in viewDidLoad, and added a "watch" for total:

    (This is Swift, but the same is true for Objective-C, too.)

    Now, if I "continue" execution (), Xcode will pause whenever this property changes and I can see at what line of code total is changing, the stack trace to get to that point, etc.

提交回复
热议问题