Swift playground with debugger support?

2019-07-16 03:36发布

问题:

Swift playgrounds in Xcode 7 don't seem to support usage of the debugger. This features seems like it would be (extremely) useful ...

I've got a playground that exercises code within a framework I'm writing. I'd really love to be able to set a breakpoint on the code within my framework -- and have the debugger stop execution when the breakpoint is hit when the code is executed from a playground. Does anyone know why playgrounds don't currently support this? Is there some fundamental reason why a playground couldn't support this or might this be a feature that could come in the future?

回答1:

There is no debugger in the Playground in Xcode. However in the right of the code, you should see the value of each expression when that line of code is executed. If it is executed multiple times, you’ll just see "(X times)”, but you can click the blue dot and see the values over time, either as a graph or a list.

If you want to print out values with the default print("") expression, make sure that you enable the assistant editor:

View > Assistant editor > Show Assistant editor



回答2:

I think that there's no need in debugger, because you can see variable value in any line, just type the name of the variable and you'll see value at that moment of execution. For for loops there's value history functionality.