Debug breakpoint in Swift Playground?
SwiftXcode6Swift PlaygroundSwift Problem Overview
I'm trying to add a breakpoint in the line # gutter, but no breakpoint is added when I do this in the playground. Is this possible or is there another way to set breakpoints in the playground?
Swift Solutions
Solution 1 - Swift
There's no debugger so you can't add any breakpoints.
Solution 2 - Swift
Matt, I could not enter code in the comments so here is a better view of using a variable on a line by itself to "debug" it.
for index in 1...5 {
dosomething(foo);
foo;
}
Then you can click the eyeball on the right hand side to see a history of foo as it was modified in the loop.
Solution 3 - Swift
If you want to pause execution of a playground to have a peek at what's going on, you can use sleep
. The information you can get isn't nearly as granular as what you can get from lldb
.
To do this, you'll need to add import Foundation
at the top of your playground.
Then, wherever you want to pause execution, you can add this:
sleep(10) // 10 second pause...you can make the number whatever you want
Solution 4 - Swift
I'm just getting my feet wet in Swift, but I think the playground idea is to show the changing state as if you ran in debug and recorded all the variable changes. There's no actual need for a breakpoint as you can see the state at any "point in time". I think it'll take me a while to get used to it, having used a debugger for > 30 years, but should be quite useful for small bits of isolated test code, especially while I'm learning the language.