6
votes

When I'm stopped in the debugger in Xcode 6, how can I view the value of a local Swift constant declared with let?

If I create a brand new Swift project in Xcode 6 and add the following two lines to application(_:didFinishLaunchingWithOptions:) in the app delegate:

let someConstant = 5
var someVariable = 6

…then run the app and break immediately after these lines, this is what I see in the variables view of the debugger:

screenshot of variables view; someVariable shows 6 and someConstant is listed twice without showing its value

Why does the variable display its value, while the constant does not? (And why is the constant listed twice?)

If, in the LLDB console, I try p, po, or fr v on someConstant (all of which correctly display the value of someVariable), I get the following:

screenshot of console; p and po both result in a "use of unresolved identifier" error and fr v displays someConstant as "empty constant data"

I'm aware that I can print the value in the debugger by using println in my source code, but I'd really rather not have to have the foresight to do that every time I simply want to inspect a value I've declared as a constant. (Even running expr println(someConstant) in the LLDB console produced the same "unresolved identifier" error as p and po.)

This should be easy. What am I missing?

1
See the second answer here: stackoverflow.com/questions/24309005/… Apparent;y this is a recognized bug.Steve Rosenberg
Do check - SWIFT_OPTIMIZATION_LEVEL stackoverflow.com/a/28518621/1294448Bishal Ghimire

1 Answers

2
votes

This was a bug in Xcode which I can confirm was fixed in Xcode 6.1. (Thanks, Steve Rosenberg.)

This is what I get now, as expected:

screenshot of console; p, po, and fr v now all display the value of someConstant in some way or another

The constant is now displayed correctly in the variables view as well, and is no longer listed twice:

screenshot of variables view; someVariable shows 6 and someConstant shows 5